]> source.dussan.org Git - jquery.git/commitdiff
Build: improve specificity of eslint config; add ecma versions
authorTimmy Willison <timmywil@users.noreply.github.com>
Thu, 6 Jun 2024 13:56:44 +0000 (09:56 -0400)
committerGitHub <noreply@github.com>
Thu, 6 Jun 2024 13:56:44 +0000 (09:56 -0400)
Closes gh-5501

15 files changed:
eslint.config.js
test/bundler_smoke_tests/run-jsdom-tests.js
test/data/csp-nonce-external.js
test/data/csp-nonce-globaleval.js
test/data/csp-nonce.js
test/jquery.js
test/unit/attributes.js
test/unit/css.js
test/unit/data.js
test/unit/deferred.js
test/unit/effects.js
test/unit/event.js
test/unit/manipulation.js
test/unit/offset.js
test/unit/traversing.js

index fb70e1a885ded66d465ecad942b4887136d2b04c..d4e57930efc4c3ada46012d052ede4b9a6aa37e6 100644 (file)
@@ -15,26 +15,6 @@ export default [
                ]
        },
 
-       {
-               files: [
-                       "eslint.config.js",
-                       "Gruntfile.cjs",
-                       "test/bundler_smoke_tests/**/*",
-                       "test/node_smoke_tests/**",
-                       "test/promises_aplus_adapters/**",
-                       "test/middleware-mockserver.cjs"
-               ],
-               languageOptions: {
-                       globals: {
-                               ...globals.node
-                       }
-               },
-               rules: {
-                       ...jqueryConfig.rules,
-                       strict: [ "error", "global" ]
-               }
-       },
-
        // Source
        {
                files: [ "src/**" ],
@@ -42,6 +22,7 @@ export default [
                        import: importPlugin
                },
                languageOptions: {
+                       ecmaVersion: 2015,
 
                        // The browser env is not enabled on purpose so that code takes
                        // all browser-only globals from window instead of assuming
@@ -84,6 +65,7 @@ export default [
                                        outerIIFEBody: 0
                                }
                        ],
+                       "no-implicit-globals": "error",
                        "one-var": [ "error", { var: "always" } ],
                        strict: [ "error", "function" ]
                }
@@ -159,7 +141,10 @@ export default [
        // Tests
        {
                files: [
-                       "test/**"
+                       "test/*",
+                       "test/data/**",
+                       "test/integration/**",
+                       "test/unit/**"
                ],
                ignores: [
                        "test/data/jquery-3.7.1.js",
@@ -170,11 +155,11 @@ export default [
                        "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,
@@ -186,32 +171,43 @@ export default [
                                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/unit/core.js"
+               ],
+               rules: {
+
+                       // Core has several cases where unused vars are expected
+                       "no-unused-vars": "off"
                }
        },
 
@@ -220,10 +216,10 @@ export default [
                        "test/runner/**/*.js"
                ],
                languageOptions: {
+                       ecmaVersion: "latest",
                        globals: {
                                ...globals.node
-                       },
-                       sourceType: "module"
+                       }
                },
                rules: {
                        ...jqueryConfig.rules
@@ -234,70 +230,80 @@ export default [
                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/unit/deferred.js"
+                       "test/data/testinit.js"
                ],
                rules: {
-
-                       // Deferred tests set strict mode for certain tests
-                       strict: "off"
+                       strict: [ "error", "global" ]
                }
        },
 
        {
                files: [
-                       "test/bundler_smoke_tests/**",
-                       "test/node_smoke_tests/**",
-                       "test/promises_aplus_adapters/**",
-                       "test/middleware-mockserver.cjs"
+                       "test/unit/deferred.js"
                ],
-               languageOptions: {
-                       globals: {
-                               ...globals.node,
-                               ...globals.es2021
-                       }
-               },
                rules: {
-                       strict: [ "error", "global" ]
+
+                       // Deferred tests set strict mode for certain tests
+                       strict: "off"
                }
        },
 
        {
                files: [
                        "build/**",
-                       "test/data/testinit.js"
+                       "eslint.config.js",
+                       "test/node_smoke_tests/**",
+                       "test/bundler_smoke_tests/**/*",
+                       "test/promises_aplus_adapters/**",
+                       "test/middleware-mockserver.cjs"
                ],
                languageOptions: {
+                       ecmaVersion: "latest",
                        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"
+                       "build/**/*.js"
                ],
                languageOptions: {
                        sourceType: "commonjs"
@@ -313,40 +319,26 @@ export default [
                        "dist-module/jquery.module.js",
                        "dist-module/jquery.slim.module.js",
                        "dist-module/jquery.factory.module.js",
-                       "dist-module/jquery.factory.slim.module.js"
-               ],
-
-               languageOptions: {
-                       globals: {
-                               ...globals.es2021,
-                               define: false,
-                               module: false,
-                               Symbol: false
-                       }
-               }
-       },
-
-       {
-               files: [
+                       "dist-module/jquery.factory.slim.module.js",
                        "dist/jquery.bundler-require-wrapper.js",
                        "dist/jquery.bundler-require-wrapper.slim.js",
                        "dist-module/jquery.node-module-wrapper.js",
                        "dist-module/jquery.node-module-wrapper.slim.js"
                ],
-
                languageOptions: {
+                       ecmaVersion: 2015,
                        globals: {
-                               ...globals.node,
-                               ...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",
 
@@ -355,5 +347,49 @@ export default [
                        "max-len": "off",
                        "one-var": "off"
                }
+       },
+
+       {
+               files: [
+                       "src/wrapper.js",
+                       "src/wrapper-factory.js",
+                       "dist/jquery.factory.js",
+                       "dist/jquery.factory.slim.js",
+                       "test/middleware-mockserver.cjs"
+               ],
+               rules: {
+                       "no-implicit-globals": "off"
+               }
+       },
+
+       {
+               files: [
+                       "dist/**"
+               ],
+               languageOptions: {
+                       ecmaVersion: 5,
+                       sourceType: "script"
+               }
+       },
+
+       {
+               files: [
+                       "dist-module/**"
+               ],
+               languageOptions: {
+                       ecmaVersion: 2015,
+                       sourceType: "module"
+               }
+       },
+
+       {
+               files: [
+                       "dist/jquery.bundler-require-wrapper.js",
+                       "dist/jquery.bundler-require-wrapper.slim.js"
+               ],
+               languageOptions: {
+                       ecmaVersion: 2015,
+                       sourceType: "commonjs"
+               }
        }
 ];
index ba7100c44e6fd580a37426ccbff0e3b1cb02c00e..f4eb548061c35a17c5c438186d816088dd3ef1d4 100644 (file)
@@ -21,7 +21,7 @@ async function runJSDOMTest( { title, folder } ) {
 
        const virtualConsole = new jsdom.VirtualConsole();
        virtualConsole.sendTo( console );
-       virtualConsole.on( "assert", ( success, message ) => {
+       virtualConsole.on( "assert", ( success ) => {
                if ( !success ) {
                        process.exitCode = 1;
                }
index efedd5a9a8697a91192f1834e9f1327a92195db6..27132b3fbe34e1d9c48b1addc554b45531312fc2 100644 (file)
@@ -1,5 +1,3 @@
-/* global startIframeTest */
-
 jQuery( function() {
        $( "body" ).append( "<script nonce='jquery+hardcoded+nonce' src='csp-nonce.js'></script>" );
 } );
index 23d549fd609eaa92beb42fe4bb1e34c4e70d7d64..8c6cb6346f2fc0277eb40250b5b1068b629b069b 100644 (file)
@@ -1,5 +1,3 @@
-/* global startIframeTest */
-
 jQuery( function() {
        $.globalEval( "startIframeTest()", { nonce: "jquery+hardcoded+nonce" } );
 } );
index 507e87e68577d563e33e6151fe4a899edeb34a14..547891df512b4587596c2f5cfa97089da7612400 100644 (file)
@@ -1,5 +1,3 @@
-/* global startIframeTest */
-
 jQuery( function() {
        var script = document.createElement( "script" );
        script.setAttribute( "nonce", "jquery+hardcoded+nonce" );
index a8a800d24efd4f07d32d48f91a1510bb770e2827..cd9c490b10b358382629dfbd2592bcabfdd70397 100644 (file)
@@ -1,7 +1,5 @@
 // Use the right jQuery source on the test page (and iframes)
 ( function() {
-       /* global loadTests: false */
-
        var dynamicImportSource, config, src,
                parentUrl = window.location.protocol + "//" + window.location.host,
                QUnit = window.QUnit;
index 477f3464a308389ed137a1d84a3548b6ab263c73..b02e99e875b73cc4566697d4d8598def136dd657 100644 (file)
@@ -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" );
index a8b7d8e892bd541c9e57914e1d9d077c39319c3b..d872e52bbe5fa06087706da8a8be46b569dfae73 100644 (file)
@@ -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( "<div></div>" )
+       var $container = jQuery( "<div></div>" )
                        .css( { position: "absolute", width: "400px", fontSize: "4px" } )
                        .appendTo( "#qunit-fixture" ),
                $el = jQuery( "<div></div>" )
index 98973c6edd637ffa65158be85ea4e8e3a34a0867..d4a0f7b12fdaf8ab3d78b3dd44e83225aeeb1701 100644 (file)
@@ -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++;
        }
index 45c94fd1dc0be33f552d441805e32a787d797fcb..1ff0e56181aab1a4af5a5225582b2352e807a630 100644 (file)
@@ -823,11 +823,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" );
                } );
index 8f6492124ef0241970a8ecbfffc285e5a1dfaf42..2ba9ee68605fc80e6304602de437b60e14410664 100644 (file)
@@ -1138,18 +1138,13 @@ QUnit.test( "interrupt toggle", function( assert ) {
 
        var longDuration = fxInterval * 200,
                shortDuration = fxInterval * 50,
-               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 ) );
                } );
index 111b1a18bcc643afa10981723b1a5915d5984a80..89d48c420aa1e56b0f285d5cba003a1e08b4afbf 100644 (file)
@@ -2698,7 +2698,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
@@ -3113,11 +3112,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" );
                        } );
 
@@ -3180,8 +3179,7 @@ QUnit.test( "trigger('click') on radio passes extra params", function( assert )
 QUnit.test( "focusout/focusin support", function( assert ) {
        assert.expect( 6 );
 
-       var focus,
-               parent = jQuery( "<div>" ),
+       var parent = jQuery( "<div>" ),
                input = jQuery( "<input>" ),
                inputExternal = jQuery( "<input>" );
 
index a3ac18eef517c480a8134c019a9a13ddf14a5cca..b91d72b298d84a66686e2f641366575b7a64a0e1 100644 (file)
@@ -1329,7 +1329,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( "<i></i>" ).children().replaceWith( function( i ) {
+               $el.html( "<i></i>" ).children().replaceWith( function() {
                        return input;
                } );
                assert.strictEqual( $el.html(), "", "replaceWith(other function returning " + label + ")" );
@@ -2661,8 +2661,6 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig
 
        assert.expect( 10 );
 
-       var elems;
-
        jQuery.each( [
                "appendTo",
                "prependTo",
@@ -2670,7 +2668,7 @@ QUnit.test( "insertAfter, insertBefore, etc do not work when destination is orig
                "insertAfter",
                "replaceAll"
        ], function( index, name ) {
-               elems = jQuery( [
+               jQuery( [
                        "<ul id='test4087-complex'><li class='test4087'><div>c1</div>h1</li><li><div>c2</div>h2</li></ul>",
                        "<div id='test4087-simple'><div class='test4087-1'>1<div class='test4087-2'>2</div><div class='test4087-3'>3</div></div></div>",
                        "<div id='test4087-multiple'><div class='test4087-multiple'>1</div><div class='test4087-multiple'>2</div></div>"
@@ -2955,7 +2953,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" );
        };
 
@@ -2973,7 +2971,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 );
@@ -2988,7 +2986,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 );
@@ -3006,7 +3004,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 );
index 50eee3dd5ddb913d56b4d348d51cb4ee85175231..a62ebde5b56717571fc603dd64b48b129e633955 100644 (file)
@@ -4,7 +4,7 @@ if ( !includesModule( "offset" ) ) {
        return;
 }
 
-var supportsScroll, alwaysScrollable,
+var alwaysScrollable,
        forceScroll = supportjQuery( "<div></div>" ).css( { width: 2000, height: 2000 } ),
        checkSupport = function( assert ) {
 
@@ -14,7 +14,7 @@ var supportsScroll, alwaysScrollable,
                // 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 - 12+
index acc9c732dc546f1195673aa5cbdb13fc580fe3fc..d3f69db815884bacd837151e92b9d6ec704a906c 100644 (file)
@@ -857,7 +857,7 @@ QUnit.testUnlessIE( "contents() for <template /> remains inert", function( asser
                "</template>"
        );
 
-       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" );