diff options
author | Timmy Willison <timmywil@users.noreply.github.com> | 2024-06-06 09:56:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-06 09:56:44 -0400 |
commit | 74970524e5e164c72ec0415267b1e057280c9455 (patch) | |
tree | b21a18d0e7f3bdab610cf3cc0a0bacc673ccc046 /eslint.config.js | |
parent | 46b9e4803ec3506e830ea6b49541ea29717ed460 (diff) | |
download | jquery-74970524e5e164c72ec0415267b1e057280c9455.tar.gz jquery-74970524e5e164c72ec0415267b1e057280c9455.zip |
Build: improve specificity of eslint config; add ecma versions
Closes gh-5501
Diffstat (limited to 'eslint.config.js')
-rw-r--r-- | eslint.config.js | 206 |
1 files changed, 121 insertions, 85 deletions
diff --git a/eslint.config.js b/eslint.config.js index fb70e1a88..d4e57930e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -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" + } } ]; |