Skip to content

Commit 1da395d

Browse files
authored
Build: Update ESLint to v9, migrate to flat config, lint dist files
Dist files linting is limited to checking if they're proper ES5. Closes gh-2336
1 parent 302b488 commit 1da395d

16 files changed

+181
-100
lines changed

.eslintignore

-4
This file was deleted.

.eslintrc.json

-21
This file was deleted.

.github/workflows/node.js.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ jobs:
4949
- name: Install npm dependencies
5050
run: npm install
5151

52-
- name: Lint
53-
run: npm run lint
54-
5552
- name: Build
5653
run: npm run build
5754

55+
# Lint must happen after build as we lint generated files.
56+
- name: Lint
57+
run: npm run lint
58+
5859
- name: Test
5960
run: |
6061
npm run test:unit -- \

Gruntfile.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,12 @@ grunt.initConfig( {
204204
"ui/**/*.js",
205205
"!ui/vendor/**/*.js",
206206
"Gruntfile.js",
207+
"dist/jquery-ui.js",
208+
"dist/jquery-ui.min.js",
207209
"build/**/*.js",
208210
"tests/unit/**/*.js",
209211
"tests/lib/**/*.js",
212+
"!tests/lib/vendor/**/*.js",
210213
"demos/**/*.js"
211214
]
212215
},
@@ -401,7 +404,7 @@ grunt.registerTask( "lint", [
401404
"htmllint"
402405
] );
403406
grunt.registerTask( "build", [ "requirejs", "concat", "minify:main" ] );
404-
grunt.registerTask( "default", [ "lint", "build" ] );
407+
grunt.registerTask( "default", [ "build", "lint" ] );
405408
grunt.registerTask( "sizer", [ "requirejs:js", "minify:main", "compare_size:all" ] );
406409
grunt.registerTask( "sizer_all", [ "requirejs:js", "minify", "compare_size" ] );
407410

demos/.eslintrc.json

-9
This file was deleted.

eslint.config.mjs

+162
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
import jqueryConfig from "eslint-config-jquery";
2+
import globals from "globals";
3+
4+
export default [
5+
{
6+
ignores: [
7+
"dist/**/*",
8+
"!dist/jquery-ui.js",
9+
"!dist/jquery-ui.min.js",
10+
"external/**/*",
11+
"tests/lib/vendor/**/*",
12+
"ui/vendor/**/*"
13+
]
14+
},
15+
16+
{
17+
ignores: [ "dist/**/*" ],
18+
rules: {
19+
...jqueryConfig.rules,
20+
"no-unused-vars": [
21+
"error",
22+
{
23+
argsIgnorePattern: "^_",
24+
caughtErrorsIgnorePattern: "^_"
25+
}
26+
]
27+
}
28+
},
29+
30+
{
31+
files: [ "Gruntfile.js" ],
32+
languageOptions: {
33+
ecmaVersion: "latest",
34+
sourceType: "commonjs",
35+
globals: {
36+
...globals.node
37+
}
38+
},
39+
rules: {
40+
strict: [ "error", "global" ]
41+
}
42+
},
43+
44+
{
45+
files: [ "eslint.config.mjs" ],
46+
languageOptions: {
47+
ecmaVersion: "latest",
48+
sourceType: "module",
49+
globals: {
50+
...globals.node
51+
}
52+
},
53+
rules: {
54+
strict: [ "error", "global" ]
55+
}
56+
},
57+
58+
// Source, demos
59+
{
60+
files: [ "ui/**/*.js", "demos/**/*.js" ],
61+
languageOptions: {
62+
ecmaVersion: 5,
63+
sourceType: "script",
64+
globals: {
65+
...globals.browser,
66+
...globals.jquery,
67+
define: false,
68+
Globalize: false
69+
}
70+
},
71+
rules: {
72+
strict: [ "error", "function" ],
73+
74+
// The following rule is relaxed due to too many violations:
75+
"no-unused-vars": [
76+
"error",
77+
{
78+
args: "after-used",
79+
argsIgnorePattern: "^_",
80+
caughtErrorsIgnorePattern: "^_"
81+
}
82+
],
83+
84+
// Too many violations:
85+
camelcase: "off",
86+
"no-nested-ternary": "off"
87+
}
88+
},
89+
{
90+
files: [ "ui/i18n/**/*.js" ],
91+
rules: {
92+
93+
// We want to keep all the strings in separate single lines
94+
"max-len": "off"
95+
}
96+
},
97+
98+
// Dist files
99+
// For dist files, we don't include any jQuery rules on purpose.
100+
// We just want to make sure the files are correct ES5.
101+
{
102+
files: [ "dist/jquery-ui.js", "dist/jquery-ui.min.js" ],
103+
languageOptions: {
104+
ecmaVersion: 5,
105+
sourceType: "script"
106+
},
107+
linterOptions: {
108+
reportUnusedDisableDirectives: "off"
109+
}
110+
},
111+
112+
// Build
113+
{
114+
files: [ "build/**/*.js" ],
115+
languageOptions: {
116+
ecmaVersion: "latest",
117+
sourceType: "commonjs",
118+
globals: {
119+
...globals.node
120+
}
121+
},
122+
rules: {
123+
"no-implicit-globals": "error",
124+
strict: [ "error", "global" ]
125+
}
126+
},
127+
128+
// Demos
129+
{
130+
files: [ "demos/**/*.js" ],
131+
languageOptions: {
132+
globals: {
133+
require: true
134+
}
135+
}
136+
},
137+
138+
// Tests
139+
{
140+
files: [ "tests/**/*.js" ],
141+
languageOptions: {
142+
ecmaVersion: 5,
143+
sourceType: "script",
144+
globals: {
145+
...globals.browser,
146+
...globals.jquery,
147+
define: false,
148+
Globalize: false,
149+
QUnit: false,
150+
require: true,
151+
requirejs: true
152+
}
153+
},
154+
"rules": {
155+
156+
// Too many violations:
157+
"max-len": "off",
158+
"no-unused-vars": "off",
159+
strict: "off" // ideally, `[ "error", "function" ]`
160+
}
161+
}
162+
];

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@
5858
"@swc/core": "1.11.5",
5959
"commitplease": "3.2.0",
6060
"eslint-config-jquery": "3.0.2",
61+
"globals": "16.0.0",
6162
"grunt": "1.6.1",
6263
"grunt-bowercopy": "1.2.5",
6364
"grunt-compare-size": "0.4.2",
6465
"grunt-contrib-concat": "2.1.0",
6566
"grunt-contrib-csslint": "2.0.0",
6667
"grunt-contrib-requirejs": "1.0.0",
67-
"grunt-eslint": "24.0.1",
68+
"grunt-eslint": "25.0.0",
6869
"grunt-git-authors": "3.2.0",
6970
"grunt-html": "17.1.0",
7071
"jquery-test-runner": "0.2.5",

ui/.eslintrc.json

-42
This file was deleted.

ui/effect.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
//>>label: Effects Core
1111
//>>group: Effects
12-
/* eslint-disable max-len */
1312
//>>description: Extends the internal jQuery effects. Includes morphing and easing. Required by all other effects.
14-
/* eslint-enable max-len */
1513
//>>docs: https://api.jqueryui.com/category/effects-core/
1614
//>>demos: https://jqueryui.com/effect/
1715

@@ -320,7 +318,7 @@ if ( $.uiBackCompat === true ) {
320318
try {
321319
// eslint-disable-next-line no-unused-expressions
322320
active.id;
323-
} catch ( e ) {
321+
} catch ( _e ) {
324322
active = document.body;
325323
}
326324

ui/effects/effect-explode.js

-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
//>>label: Explode Effect
1111
//>>group: Effects
12-
/* eslint-disable max-len */
1312
//>>description: Explodes an element in all directions into n pieces. Implodes an element to its original wholeness.
14-
/* eslint-enable max-len */
1513
//>>docs: https://api.jqueryui.com/explode-effect/
1614
//>>demos: https://jqueryui.com/effect/
1715

ui/widgets/accordion.js

-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
//>>label: Accordion
1111
//>>group: Widgets
12-
/* eslint-disable max-len */
1312
//>>description: Displays collapsible content panels for presenting information in a limited amount of space.
14-
/* eslint-enable max-len */
1513
//>>docs: https://api.jqueryui.com/accordion/
1614
//>>demos: https://jqueryui.com/accordion/
1715
//>>css.structure: ../../themes/base/core.css

ui/widgets/datepicker.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable max-len, camelcase */
1+
/* eslint-disable max-len */
22
/*!
33
* jQuery UI Datepicker @VERSION
44
* https://jqueryui.com
@@ -535,7 +535,7 @@ $.extend( Datepicker.prototype, {
535535
_getInst: function( target ) {
536536
try {
537537
return $.data( target, "datepicker" );
538-
} catch ( err ) {
538+
} catch ( _err ) {
539539
throw "Missing instance data for this datepicker";
540540
}
541541
},
@@ -768,7 +768,7 @@ $.extend( Datepicker.prototype, {
768768
$.datepicker._updateAlternate( inst );
769769
$.datepicker._updateDatepicker( inst );
770770
}
771-
} catch ( err ) {
771+
} catch ( _err ) {
772772
}
773773
}
774774
return true;
@@ -1540,7 +1540,7 @@ $.extend( Datepicker.prototype, {
15401540

15411541
try {
15421542
date = this.parseDate( dateFormat, dates, settings ) || defaultDate;
1543-
} catch ( event ) {
1543+
} catch ( _err ) {
15441544
dates = ( noDefault ? "" : dates );
15451545
}
15461546
inst.selectedDay = date.getDate();
@@ -1569,7 +1569,7 @@ $.extend( Datepicker.prototype, {
15691569
try {
15701570
return $.datepicker.parseDate( $.datepicker._get( inst, "dateFormat" ),
15711571
offset, $.datepicker._getFormatConfig( inst ) );
1572-
} catch ( e ) {
1572+
} catch ( _e ) {
15731573

15741574
// Ignore
15751575
}

ui/widgets/progressbar.js

-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99

1010
//>>label: Progressbar
1111
//>>group: Widgets
12-
/* eslint-disable max-len */
1312
//>>description: Displays a status indicator for loading state, standard percentage, and other progress indicators.
14-
/* eslint-enable max-len */
1513
//>>docs: https://api.jqueryui.com/progressbar/
1614
//>>demos: https://jqueryui.com/progressbar/
1715
//>>css.structure: ../../themes/base/core.css

ui/widgets/resizable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ $.widget( "ui.resizable", $.ui.mouse, {
104104
el[ scroll ] = 1;
105105
has = ( el[ scroll ] > 0 );
106106
el[ scroll ] = 0;
107-
} catch ( e ) {
107+
} catch ( _e ) {
108108

109109
// `el` might be a string, then setting `scroll` will throw
110110
// an error in strict mode; ignore it.

0 commit comments

Comments
 (0)