Skip to content

Commit 82169df

Browse files
authored
Build: improve specificity of eslint config; add ecma versions
- also added no-implicit-globals rule outside of tests, but including dist Close jquerygh-5504
1 parent efa1e0a commit 82169df

15 files changed

+125
-117
lines changed

eslint.config.js

Lines changed: 100 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,11 @@ module.exports = [
1515
]
1616
},
1717

18-
{
19-
files: [
20-
"eslint.config.js",
21-
"Gruntfile.js",
22-
"test/node_smoke_tests/**",
23-
"test/promises_aplus_adapters/**",
24-
"test/middleware-mockserver.js"
25-
],
26-
languageOptions: {
27-
globals: {
28-
...globals.node
29-
},
30-
sourceType: "commonjs"
31-
},
32-
rules: {
33-
...jqueryConfig.rules,
34-
strict: [ "error", "global" ]
35-
}
36-
},
37-
3818
// Source
3919
{
4020
files: [ "src/**" ],
4121
languageOptions: {
22+
ecmaVersion: 2015,
4223

4324
// The browser env is not enabled on purpose so that code takes
4425
// all browser-only globals from window instead of assuming
@@ -65,6 +46,7 @@ module.exports = [
6546
]
6647
}
6748
],
49+
"no-implicit-globals": "error",
6850
"one-var": [ "error", { var: "always" } ],
6951
strict: [ "error", "function" ]
7052
}
@@ -117,7 +99,10 @@ module.exports = [
11799
// Tests
118100
{
119101
files: [
120-
"test/**"
102+
"test/*",
103+
"test/data/**",
104+
"test/integration/**",
105+
"test/unit/**"
121106
],
122107
ignores: [
123108
"test/data/jquery-3.7.1.js",
@@ -128,11 +113,11 @@ module.exports = [
128113
"test/data/core/jquery-iterability-transpiled.js"
129114
],
130115
languageOptions: {
116+
ecmaVersion: 2015,
117+
sourceType: "script",
131118
globals: {
132119
...globals.browser,
133120
require: false,
134-
Promise: false,
135-
Symbol: false,
136121
trustedTypes: false,
137122
QUnit: false,
138123
ajaxTest: false,
@@ -144,32 +129,54 @@ module.exports = [
144129
moduleTeardown: false,
145130
url: false,
146131
q: false,
147-
jQuery: true,
148-
sinon: true,
149-
amdDefined: true,
150-
fireNative: true,
151-
Globals: true,
152-
hasPHP: true,
153-
isLocal: true,
154-
supportjQuery: true,
155-
originaljQuery: true,
156-
$: true,
157-
original$: true,
158-
baseURL: true,
159-
externalHost: true
132+
jQuery: false,
133+
$: false,
134+
sinon: false,
135+
amdDefined: false,
136+
fireNative: false,
137+
Globals: false,
138+
hasPHP: false,
139+
isLocal: false,
140+
supportjQuery: false,
141+
originaljQuery: false,
142+
original$: false,
143+
baseURL: false,
144+
externalHost: false
160145
}
161146
},
162147
rules: {
163148
...jqueryConfig.rules,
164-
strict: [ "error", "function" ],
165149

166-
// See https://github.com/eslint/eslint/issues/2342
167-
"no-unused-vars": "off",
150+
"no-unused-vars": [
151+
"error",
152+
{ args: "after-used", argsIgnorePattern: "^_" }
153+
],
168154

169155
// Too many errors
170156
"max-len": "off",
171-
camelcase: "off",
172-
"one-var": "off"
157+
camelcase: "off"
158+
}
159+
},
160+
161+
{
162+
files: [
163+
"test/jquery.js"
164+
],
165+
languageOptions: {
166+
globals: {
167+
loadTests: false
168+
}
169+
}
170+
},
171+
172+
{
173+
files: [
174+
"test/unit/core.js"
175+
],
176+
rules: {
177+
178+
// Core has several cases where unused vars are expected
179+
"no-unused-vars": "off"
173180
}
174181
},
175182

@@ -178,86 +185,99 @@ module.exports = [
178185
"test/runner/**/*.js"
179186
],
180187
languageOptions: {
188+
ecmaVersion: "latest",
181189
globals: {
182190
...globals.node
183-
},
184-
sourceType: "module"
191+
}
185192
},
186193
rules: {
187-
...jqueryConfig.rules
194+
...jqueryConfig.rules,
195+
"no-implicit-globals": "error"
188196
}
189197
},
190198

191199
{
192200
files: [ "test/runner/listeners.js" ],
193201
languageOptions: {
194202
ecmaVersion: 5,
195-
sourceType: "script"
203+
sourceType: "script",
204+
globals: {
205+
...globals.browser,
206+
QUnit: false,
207+
Symbol: false
208+
}
196209
}
197210
},
198211

199212
{
200213
files: [
214+
"test/data/testinit.js",
201215
"test/data/testrunner.js",
202216
"test/data/core/jquery-iterability-transpiled-es6.js"
203217
],
204218
languageOptions: {
205-
sourceType: "script"
219+
ecmaVersion: 2015,
220+
sourceType: "script",
221+
globals: {
222+
...globals.browser
223+
}
224+
},
225+
rules: {
226+
...jqueryConfig.rules,
227+
strict: [ "error", "function" ]
206228
}
207229
},
208230

209231
{
210232
files: [
211-
"test/unit/deferred.js"
233+
"test/data/testinit.js"
212234
],
213235
rules: {
214-
215-
// Deferred tests set strict mode for certain tests
216-
strict: "off"
236+
strict: [ "error", "global" ]
217237
}
218238
},
219239

220240
{
221241
files: [
222-
"test/node_smoke_tests/**",
223-
"test/promises_aplus_adapters/**",
224-
"test/middleware-mockserver.js"
242+
"test/unit/deferred.js"
225243
],
226-
languageOptions: {
227-
globals: {
228-
...globals.node,
229-
...globals.es2021
230-
}
231-
},
232244
rules: {
233-
strict: [ "error", "global" ]
245+
246+
// Deferred tests set strict mode for certain tests
247+
strict: "off"
234248
}
235249
},
236250

237251
{
238252
files: [
239253
"build/**",
240-
"test/data/testinit.js"
254+
"eslint.config.js",
255+
"test/node_smoke_tests/**",
256+
"test/bundler_smoke_tests/**/*",
257+
"test/promises_aplus_adapters/**",
258+
"test/middleware-mockserver.js"
241259
],
242260
languageOptions: {
261+
ecmaVersion: "latest",
262+
sourceType: "commonjs",
243263
globals: {
244-
...globals.node,
245-
...globals.es2021
264+
...globals.browser,
265+
...globals.node
246266
}
247267
},
248268
rules: {
249269
...jqueryConfig.rules,
270+
"no-implicit-globals": "error",
250271
strict: [ "error", "global" ]
251272
}
252273
},
253274

254275
{
255276
files: [
256-
"build/**/*.js",
257-
"test/data/testinit.js"
277+
"**/*.mjs"
258278
],
259279
languageOptions: {
260-
sourceType: "commonjs"
280+
sourceType: "module"
261281
}
262282
},
263283

@@ -266,20 +286,19 @@ module.exports = [
266286
"dist/jquery.js",
267287
"dist/jquery.slim.js"
268288
],
269-
270289
languageOptions: {
271290
globals: {
272-
...globals.browser,
273-
...globals.es2021,
274291
define: false,
275292
module: false,
276-
Symbol: false
293+
Symbol: false,
294+
window: false
277295
}
278296
},
279-
280297
rules: {
281298
...jqueryConfig.rules,
282299

300+
"no-implicit-globals": "error",
301+
283302
// That is okay for the built version
284303
"no-multiple-empty-lines": "off",
285304

@@ -288,5 +307,15 @@ module.exports = [
288307
"max-len": "off",
289308
"one-var": "off"
290309
}
310+
},
311+
312+
{
313+
files: [
314+
"dist/**"
315+
],
316+
languageOptions: {
317+
ecmaVersion: 5,
318+
sourceType: "script"
319+
}
291320
}
292321
];

test/data/csp-nonce-external.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* global startIframeTest */
2-
31
jQuery( function() {
42
$( "body" ).append( "<script nonce='jquery+hardcoded+nonce' src='csp-nonce.js'></script>" );
53
} );

test/data/csp-nonce-globaleval.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* global startIframeTest */
2-
31
jQuery( function() {
42
$.globalEval( "startIframeTest()", { nonce: "jquery+hardcoded+nonce" } );
53
} );

test/data/csp-nonce.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/* global startIframeTest */
2-
31
jQuery( function() {
42
var script = document.createElement( "script" );
53
script.setAttribute( "nonce", "jquery+hardcoded+nonce" );

test/jquery.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Use the right jQuery source on the test page (and iframes)
22
( function() {
3-
/* global loadTests: false */
4-
53
var config, src,
64
parentUrl = window.location.protocol + "//" + window.location.host,
75
QUnit = window.QUnit,

test/unit/attributes.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ QUnit.test( "attr(String, Object)", function( assert ) {
261261

262262
var $input, $text, $details,
263263
attributeNode, commentNode, textNode, obj,
264-
table, td, j, type,
264+
table, td, j,
265265
check, thrown, button, $radio, $radios, $svg,
266266
div = jQuery( "#qunit-fixture div" ).attr( "foo", "bar" ),
267267
i = 0,
@@ -418,7 +418,6 @@ QUnit.test( "attr(String, Object)", function( assert ) {
418418
j.removeAttr( "name" );
419419

420420
// Type
421-
type = jQuery( "#check2" ).attr( "type" );
422421
try {
423422
jQuery( "#check2" ).attr( "type", "hidden" );
424423
assert.ok( true, "No exception thrown on input type change" );

test/unit/css.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ QUnit.test( "css(String|Hash)", function( assert ) {
77

88
assert.equal( jQuery( "#qunit-fixture" ).css( "display" ), "block", "Check for css property \"display\"" );
99

10-
var $child, div, div2, width, height, child, prctval, checkval, old;
10+
var $child, div, div2, child, prctval, checkval, old;
1111

1212
$child = jQuery( "#nothiddendivchild" ).css( { "width": "20%", "height": "20%" } );
1313
assert.notEqual( $child.css( "width" ), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" );
@@ -36,8 +36,6 @@ QUnit.test( "css(String|Hash)", function( assert ) {
3636
// handle negative numbers by setting to zero trac-11604
3737
jQuery( "#nothiddendiv" ).css( { "width": 1, "height": 1 } );
3838

39-
width = parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) );
40-
height = parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) );
4139
jQuery( "#nothiddendiv" ).css( { "overflow": "hidden", "width": -1, "height": -1 } );
4240
assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ), 0, "Test negative width set to 0" );
4341
assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ), 0, "Test negative height set to 0" );
@@ -274,8 +272,7 @@ QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) {
274272
QUnit.test( "css() mismatched relative values with bounded styles (gh-2144)", function( assert ) {
275273
assert.expect( 1 );
276274

277-
var right,
278-
$container = jQuery( "<div></div>" )
275+
var $container = jQuery( "<div></div>" )
279276
.css( { position: "absolute", width: "400px", fontSize: "4px" } )
280277
.appendTo( "#qunit-fixture" ),
281278
$el = jQuery( "<div></div>" )

test/unit/data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ QUnit.test( "data-* attributes", function( assert ) {
317317

318318
assert.equal( num, check.length, "Make sure that the right number of properties came through." );
319319

320+
/* eslint-disable-next-line no-unused-vars */
320321
for ( prop in obj2 ) {
321322
num2++;
322323
}

test/unit/deferred.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,11 +861,11 @@ QUnit.test( "jQuery.when(nonThenable) - like Promise.resolve", function( assert
861861
done = assert.async( 20 );
862862

863863
jQuery.when()
864-
.done( function( resolveValue ) {
864+
.done( function() {
865865
assert.strictEqual( arguments.length, 0, "Resolved .done with no arguments" );
866866
assert.strictEqual( this, defaultContext, "Default .done context with no arguments" );
867867
} )
868-
.then( function( resolveValue ) {
868+
.then( function() {
869869
assert.strictEqual( arguments.length, 0, "Resolved .then with no arguments" );
870870
assert.strictEqual( this, defaultContext, "Default .then context with no arguments" );
871871
} );

0 commit comments

Comments
 (0)