diff --git a/eslint.config.js b/eslint.config.js index 85d3d85b4..b7e3c702e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -15,30 +15,11 @@ module.exports = [ ] }, - { - files: [ - "eslint.config.js", - "Gruntfile.js", - "test/node_smoke_tests/**", - "test/promises_aplus_adapters/**", - "test/middleware-mockserver.js" - ], - languageOptions: { - globals: { - ...globals.node - }, - sourceType: "commonjs" - }, - rules: { - ...jqueryConfig.rules, - strict: [ "error", "global" ] - } - }, - // Source { files: [ "src/**" ], languageOptions: { + ecmaVersion: 2015, // The browser env is not enabled on purpose so that code takes // all browser-only globals from window instead of assuming @@ -65,6 +46,7 @@ module.exports = [ ] } ], + "no-implicit-globals": "error", "one-var": [ "error", { var: "always" } ], strict: [ "error", "function" ] } @@ -117,7 +99,10 @@ module.exports = [ // Tests { files: [ - "test/**" + "test/*", + "test/data/**", + "test/integration/**", + "test/unit/**" ], ignores: [ "test/data/jquery-3.7.1.js", @@ -128,11 +113,11 @@ module.exports = [ "test/data/core/jquery-iterability-transpiled.js" ], languageOptions: { + ecmaVersion: 2015, + sourceType: "script", globals: { ...globals.browser, require: false, - Promise: false, - Symbol: false, trustedTypes: false, QUnit: false, ajaxTest: false, @@ -144,32 +129,54 @@ module.exports = [ moduleTeardown: false, url: false, q: false, - jQuery: true, - sinon: true, - amdDefined: true, - fireNative: true, - Globals: true, - hasPHP: true, - isLocal: true, - supportjQuery: true, - originaljQuery: true, - $: true, - original$: true, - baseURL: true, - externalHost: true + jQuery: false, + $: false, + sinon: false, + amdDefined: false, + fireNative: false, + Globals: false, + hasPHP: false, + isLocal: false, + supportjQuery: false, + originaljQuery: false, + original$: false, + baseURL: false, + externalHost: false } }, rules: { ...jqueryConfig.rules, - strict: [ "error", "function" ], - // See https://github.com/eslint/eslint/issues/2342 - "no-unused-vars": "off", + "no-unused-vars": [ + "error", + { args: "after-used", argsIgnorePattern: "^_" } + ], // Too many errors "max-len": "off", - camelcase: "off", - "one-var": "off" + camelcase: "off" + } + }, + + { + files: [ + "test/jquery.js" + ], + languageOptions: { + globals: { + loadTests: false + } + } + }, + + { + files: [ + "test/unit/core.js" + ], + rules: { + + // Core has several cases where unused vars are expected + "no-unused-vars": "off" } }, @@ -178,13 +185,14 @@ module.exports = [ "test/runner/**/*.js" ], languageOptions: { + ecmaVersion: "latest", globals: { ...globals.node - }, - sourceType: "module" + } }, rules: { - ...jqueryConfig.rules + ...jqueryConfig.rules, + "no-implicit-globals": "error" } }, @@ -192,17 +200,40 @@ module.exports = [ files: [ "test/runner/listeners.js" ], languageOptions: { ecmaVersion: 5, - sourceType: "script" + sourceType: "script", + globals: { + ...globals.browser, + QUnit: false, + Symbol: false + } } }, { files: [ + "test/data/testinit.js", "test/data/testrunner.js", "test/data/core/jquery-iterability-transpiled-es6.js" ], languageOptions: { - sourceType: "script" + ecmaVersion: 2015, + sourceType: "script", + globals: { + ...globals.browser + } + }, + rules: { + ...jqueryConfig.rules, + strict: [ "error", "function" ] + } + }, + + { + files: [ + "test/data/testinit.js" + ], + rules: { + strict: [ "error", "global" ] } }, @@ -219,45 +250,34 @@ module.exports = [ { files: [ + "build/**", + "eslint.config.js", "test/node_smoke_tests/**", + "test/bundler_smoke_tests/**/*", "test/promises_aplus_adapters/**", "test/middleware-mockserver.js" ], languageOptions: { + ecmaVersion: "latest", + sourceType: "commonjs", globals: { - ...globals.node, - ...globals.es2021 - } - }, - rules: { - strict: [ "error", "global" ] - } - }, - - { - files: [ - "build/**", - "test/data/testinit.js" - ], - languageOptions: { - globals: { - ...globals.node, - ...globals.es2021 + ...globals.browser, + ...globals.node } }, rules: { ...jqueryConfig.rules, + "no-implicit-globals": "error", strict: [ "error", "global" ] } }, { files: [ - "build/**/*.js", - "test/data/testinit.js" + "**/*.mjs" ], languageOptions: { - sourceType: "commonjs" + sourceType: "module" } }, @@ -266,20 +286,19 @@ module.exports = [ "dist/jquery.js", "dist/jquery.slim.js" ], - languageOptions: { globals: { - ...globals.browser, - ...globals.es2021, define: false, module: false, - Symbol: false + Symbol: false, + window: false } }, - rules: { ...jqueryConfig.rules, + "no-implicit-globals": "error", + // That is okay for the built version "no-multiple-empty-lines": "off", @@ -288,5 +307,15 @@ module.exports = [ "max-len": "off", "one-var": "off" } + }, + + { + files: [ + "dist/**" + ], + languageOptions: { + ecmaVersion: 5, + sourceType: "script" + } } ]; diff --git a/test/data/csp-nonce-external.js b/test/data/csp-nonce-external.js index efedd5a9a..27132b3fb 100644 --- a/test/data/csp-nonce-external.js +++ b/test/data/csp-nonce-external.js @@ -1,5 +1,3 @@ -/* global startIframeTest */ - jQuery( function() { $( "body" ).append( "" ); } ); diff --git a/test/data/csp-nonce-globaleval.js b/test/data/csp-nonce-globaleval.js index 23d549fd6..8c6cb6346 100644 --- a/test/data/csp-nonce-globaleval.js +++ b/test/data/csp-nonce-globaleval.js @@ -1,5 +1,3 @@ -/* global startIframeTest */ - jQuery( function() { $.globalEval( "startIframeTest()", { nonce: "jquery+hardcoded+nonce" } ); } ); diff --git a/test/data/csp-nonce.js b/test/data/csp-nonce.js index 507e87e68..547891df5 100644 --- a/test/data/csp-nonce.js +++ b/test/data/csp-nonce.js @@ -1,5 +1,3 @@ -/* global startIframeTest */ - jQuery( function() { var script = document.createElement( "script" ); script.setAttribute( "nonce", "jquery+hardcoded+nonce" ); diff --git a/test/jquery.js b/test/jquery.js index 779e4367b..70a59322f 100644 --- a/test/jquery.js +++ b/test/jquery.js @@ -1,7 +1,5 @@ // Use the right jQuery source on the test page (and iframes) ( function() { - /* global loadTests: false */ - var config, src, parentUrl = window.location.protocol + "//" + window.location.host, QUnit = window.QUnit, diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 7cc6d1f7e..095404ab2 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -261,7 +261,7 @@ QUnit.test( "attr(String, Object)", function( assert ) { var $input, $text, $details, attributeNode, commentNode, textNode, obj, - table, td, j, type, + table, td, j, check, thrown, button, $radio, $radios, $svg, div = jQuery( "#qunit-fixture div" ).attr( "foo", "bar" ), i = 0, @@ -418,7 +418,6 @@ QUnit.test( "attr(String, Object)", function( assert ) { j.removeAttr( "name" ); // Type - type = jQuery( "#check2" ).attr( "type" ); try { jQuery( "#check2" ).attr( "type", "hidden" ); assert.ok( true, "No exception thrown on input type change" ); diff --git a/test/unit/css.js b/test/unit/css.js index 851c5f68f..df0da5222 100644 --- a/test/unit/css.js +++ b/test/unit/css.js @@ -7,7 +7,7 @@ QUnit.test( "css(String|Hash)", function( assert ) { assert.equal( jQuery( "#qunit-fixture" ).css( "display" ), "block", "Check for css property \"display\"" ); - var $child, div, div2, width, height, child, prctval, checkval, old; + var $child, div, div2, child, prctval, checkval, old; $child = jQuery( "#nothiddendivchild" ).css( { "width": "20%", "height": "20%" } ); 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 ) { // handle negative numbers by setting to zero trac-11604 jQuery( "#nothiddendiv" ).css( { "width": 1, "height": 1 } ); - width = parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ); - height = parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ); jQuery( "#nothiddendiv" ).css( { "overflow": "hidden", "width": -1, "height": -1 } ); assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ), 0, "Test negative width set to 0" ); 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 ) { QUnit.test( "css() mismatched relative values with bounded styles (gh-2144)", function( assert ) { assert.expect( 1 ); - var right, - $container = jQuery( "
" ) + var $container = jQuery( "
" ) .css( { position: "absolute", width: "400px", fontSize: "4px" } ) .appendTo( "#qunit-fixture" ), $el = jQuery( "
" ) diff --git a/test/unit/data.js b/test/unit/data.js index 1a377a547..04893a64c 100644 --- a/test/unit/data.js +++ b/test/unit/data.js @@ -317,6 +317,7 @@ QUnit.test( "data-* attributes", function( assert ) { assert.equal( num, check.length, "Make sure that the right number of properties came through." ); + /* eslint-disable-next-line no-unused-vars */ for ( prop in obj2 ) { num2++; } diff --git a/test/unit/deferred.js b/test/unit/deferred.js index 4c750bb6c..fe9d93f1a 100644 --- a/test/unit/deferred.js +++ b/test/unit/deferred.js @@ -861,11 +861,11 @@ QUnit.test( "jQuery.when(nonThenable) - like Promise.resolve", function( assert done = assert.async( 20 ); jQuery.when() - .done( function( resolveValue ) { + .done( function() { assert.strictEqual( arguments.length, 0, "Resolved .done with no arguments" ); assert.strictEqual( this, defaultContext, "Default .done context with no arguments" ); } ) - .then( function( resolveValue ) { + .then( function() { assert.strictEqual( arguments.length, 0, "Resolved .then with no arguments" ); assert.strictEqual( this, defaultContext, "Default .then context with no arguments" ); } ); diff --git a/test/unit/effects.js b/test/unit/effects.js index aa3d0ccb7..4bb5e26b8 100644 --- a/test/unit/effects.js +++ b/test/unit/effects.js @@ -1162,21 +1162,15 @@ QUnit.test( "jQuery.show('fast') doesn't clear radio buttons (bug trac-1095)", f QUnit.test( "interrupt toggle", function( assert ) { assert.expect( 24 ); - var env = this, - longDuration = 2000, + var longDuration = 2000, shortDuration = 500, - remaining = 0, $elems = jQuery( ".chain-test" ), clock = this.clock, - finish = function() { - }; + finish = function() {}; jQuery.each( { slideToggle: "height", fadeToggle: "opacity", toggle: "width" }, function( method, prop ) { var $methodElems = $elems.filter( "[id^='" + method.toLowerCase() + "']" ).each( function() { - // Don't end test until we're done with this element - remaining++; - // Save original property value for comparison jQuery.data( this, "startVal", jQuery( this ).css( prop ) ); } ); @@ -1596,7 +1590,7 @@ QUnit.test( "User supplied callback called after show when fx off (trac-8892)", QUnit.test( "animate should set display for disconnected nodes", function( assert ) { assert.expect( 20 ); - var env = this, + var clock = this.clock, showMethods = { fadeIn: [], fadeTo: [ "fast", 0.5 ], @@ -1613,8 +1607,7 @@ QUnit.test( "animate should set display for disconnected nodes", function( asser $divNone = jQuery( "
" ), $divInline = jQuery( "
" ), nullParentDisplay = $divEmpty.css( "display" ), - underFragmentDisplay = $divTest.css( "display" ), - clock = this.clock; + underFragmentDisplay = $divTest.css( "display" ); assert.strictEqual( $divEmpty[ 0 ].parentNode, null, "Setup: element with null parentNode" ); assert.strictEqual( ( $divTest[ 0 ].parentNode || {} ).nodeType, 11, "Setup: element under fragment" ); diff --git a/test/unit/event.js b/test/unit/event.js index ce7c9b1fb..b1d5bde56 100644 --- a/test/unit/event.js +++ b/test/unit/event.js @@ -2676,7 +2676,6 @@ testIframe( assert.expect( 1 ); var done = assert.async(), - focus = false, input = jQuery( frameDoc ).find( "#frame-input" ); // Create a focusin handler on the parent; shouldn't affect the iframe's fate @@ -2692,7 +2691,6 @@ testIframe( } ); input.on( "focusin", function() { - focus = true; assert.ok( true, "fired a focusin event in the iframe" ); } ); @@ -3091,11 +3089,11 @@ QUnit.test( spy.immediate = sinon.stub( event.originalEvent, "stopImmediatePropagation" ); event.stopImmediatePropagation(); } ) - .on( "simulated", function( event ) { + .on( "simulated", function() { assert.ok( false, "simulated event immediate propagation stopped" ); } ); outer - .on( "simulated", function( event ) { + .on( "simulated", function() { assert.ok( false, "simulated event propagation stopped" ); } ); diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index b7fd786d7..7f356432a 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1369,7 +1369,7 @@ QUnit.test( "Empty replaceWith (trac-13401; trac-13596; gh-2204)", function( ass return input; } ); assert.strictEqual( $el.html(), "", "replaceWith(function returning " + label + ")" ); - $el.html( "" ).children().replaceWith( function( i ) { + $el.html( "" ).children().replaceWith( function() { return input; } ); assert.strictEqual( $el.html(), "", "replaceWith(other function returning " + label + ")" ); @@ -2679,8 +2679,6 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig assert.expect( 10 ); - var elems; - jQuery.each( [ "appendTo", "prependTo", @@ -2688,7 +2686,7 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig "insertAfter", "replaceAll" ], function( index, name ) { - elems = jQuery( [ + jQuery( [ "", "
1
2
3
", "
1
2
" @@ -2971,7 +2969,7 @@ QUnit.test( "Ignore content from unsuccessful responses (gh-4126)", function( as assert.expect( 1 ); var globalEval = jQuery.globalEval; - jQuery.globalEval = function( code ) { + jQuery.globalEval = function( _code ) { assert.ok( false, "no attempt to evaluate code from an unsuccessful response" ); }; @@ -2989,7 +2987,7 @@ QUnit.test( "Ignore content from unsuccessful responses (gh-4126)", function( as testIframe( "Check if CSP nonce is preserved", "mock.php?action=cspNonce", - function( assert, jQuery, window, document ) { + function( assert ) { var done = assert.async(); assert.expect( 1 ); @@ -3012,7 +3010,7 @@ testIframe( testIframe( "Check if CSP nonce is preserved for external scripts with src attribute", "mock.php?action=cspNonce&test=external", - function( assert, jQuery, window, document ) { + function( assert ) { var done = assert.async(); assert.expect( 1 ); @@ -3036,7 +3034,7 @@ testIframe( testIframe( "jQuery.globalEval supports nonce", "mock.php?action=cspNonce&test=globaleval", - function( assert, jQuery, window, document ) { + function( assert ) { var done = assert.async(); assert.expect( 1 ); diff --git a/test/unit/offset.js b/test/unit/offset.js index f3d611360..d507c38f1 100644 --- a/test/unit/offset.js +++ b/test/unit/offset.js @@ -4,7 +4,7 @@ if ( !includesModule( "offset" ) ) { return; } -var supportsFixedPosition, supportsScroll, alwaysScrollable, +var alwaysScrollable, forceScroll = supportjQuery( "
" ).css( { width: 2000, height: 2000 } ), checkSupport = function( assert ) { @@ -14,13 +14,13 @@ var supportsFixedPosition, supportsScroll, alwaysScrollable, var checkFixed = supportjQuery( "
" ) .css( { position: "fixed", top: "20px" } ) .appendTo( "#qunit-fixture" ); - supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20; + window.supportsFixedPosition = checkFixed[ 0 ].offsetTop === 20; checkFixed.remove(); // Append forceScroll to the body instead of #qunit-fixture because the latter is hidden forceScroll.appendTo( "body" ); window.scrollTo( 200, 200 ); - supportsScroll = document.documentElement.scrollTop || document.body.scrollTop; + window.supportsScroll = document.documentElement.scrollTop || document.body.scrollTop; forceScroll.detach(); // Support: iOS <=7 diff --git a/test/unit/selector.js b/test/unit/selector.js index 9867aaf18..864e54a90 100644 --- a/test/unit/selector.js +++ b/test/unit/selector.js @@ -1497,8 +1497,9 @@ QUnit.test( "pseudo - a:(dis|en)abled", function( assert ) { assert.expect( 2 ); var enabled, disabled, - container = jQuery( "
" ), - anchor = jQuery( "Link" ); + container = jQuery( "
" ); + + jQuery( "Link" ).appendTo( container ); container.appendTo( "#qunit-fixture" ); diff --git a/test/unit/traversing.js b/test/unit/traversing.js index cb2b5b145..d105e172e 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -849,7 +849,7 @@ QUnit[ "content" in document.createElement( "template" ) ? "test" : "skip" ]( "c "" ); - var content = jQuery( "#template" ).contents(); + jQuery( "#template" ).contents(); assert.strictEqual( window.testScript, true, "script in template isn't executed" ); assert.strictEqual( window.testImgOnload, true, "onload of image in template isn't executed" );