2023-09-18 16:39:00 +00:00
|
|
|
import jqueryConfig from "eslint-config-jquery";
|
|
|
|
import importPlugin from "eslint-plugin-import";
|
|
|
|
import globals from "globals";
|
|
|
|
|
|
|
|
export default [
|
|
|
|
{
|
|
|
|
|
|
|
|
// Only global ignores will bypass the parser
|
|
|
|
// and avoid JS parsing errors
|
|
|
|
// See https://github.com/eslint/eslint/discussions/17412
|
|
|
|
ignores: [
|
|
|
|
"external",
|
2024-08-09 01:39:11 +00:00
|
|
|
"tmp",
|
2024-06-15 13:11:34 +00:00
|
|
|
"test/data/json_obj.js",
|
|
|
|
"test/data/jquery-*.js"
|
2023-09-18 16:39:00 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
|
|
|
|
// Source
|
|
|
|
{
|
|
|
|
files: [ "src/**" ],
|
|
|
|
plugins: {
|
|
|
|
import: importPlugin
|
|
|
|
},
|
|
|
|
languageOptions: {
|
2024-06-06 13:56:44 +00:00
|
|
|
ecmaVersion: 2015,
|
2023-09-18 16:39:00 +00:00
|
|
|
|
|
|
|
// The browser env is not enabled on purpose so that code takes
|
|
|
|
// all browser-only globals from window instead of assuming
|
|
|
|
// they're available as globals. This makes it possible to use
|
|
|
|
// jQuery with tools like jsdom which provide a custom window
|
|
|
|
// implementation.
|
|
|
|
globals: {
|
|
|
|
window: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...jqueryConfig.rules,
|
|
|
|
"import/extensions": [ "error", "always" ],
|
|
|
|
"import/no-cycle": "error",
|
|
|
|
|
|
|
|
// TODO: Enable this rule when eslint-plugin-import supports
|
|
|
|
// it when using flat config.
|
|
|
|
// See https://github.com/import-js/eslint-plugin-import/issues/2556
|
|
|
|
|
|
|
|
// "import/no-unused-modules": [
|
|
|
|
// "error",
|
|
|
|
// {
|
|
|
|
// unusedExports: true,
|
|
|
|
|
|
|
|
// // When run via WebStorm, the root path against which these paths
|
|
|
|
// // are resolved is the path where this ESLint config file lies,
|
|
|
|
// // i.e. `src`. When run via the command line, it's usually the root
|
|
|
|
// // folder of the jQuery repository. This pattern intends to catch both.
|
|
|
|
// // Note that we cannot specify two patterns here:
|
|
|
|
// // [ "src/*.js", "*.js" ]
|
|
|
|
// // as they're analyzed individually and the rule crashes if a pattern
|
|
|
|
// // cannot be matched.
|
|
|
|
// ignoreExports: [ "{src/,}*.js" ]
|
|
|
|
// }
|
|
|
|
// ],
|
|
|
|
indent: [
|
|
|
|
"error",
|
|
|
|
"tab",
|
|
|
|
{
|
|
|
|
outerIIFEBody: 0
|
|
|
|
}
|
|
|
|
],
|
2024-06-06 13:56:44 +00:00
|
|
|
"no-implicit-globals": "error",
|
2024-08-09 01:39:11 +00:00
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{ caughtErrorsIgnorePattern: "^_" }
|
|
|
|
],
|
2023-09-18 16:39:00 +00:00
|
|
|
"one-var": [ "error", { var: "always" } ],
|
|
|
|
strict: [ "error", "function" ]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-09-19 16:58:24 +00:00
|
|
|
files: [
|
|
|
|
"src/wrapper.js",
|
|
|
|
"src/wrapper-esm.js",
|
|
|
|
"src/wrapper-factory.js",
|
|
|
|
"src/wrapper-factory-esm.js"
|
|
|
|
],
|
2023-09-18 16:39:00 +00:00
|
|
|
languageOptions: {
|
|
|
|
globals: {
|
2023-09-19 16:58:24 +00:00
|
|
|
jQuery: false
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
"no-unused-vars": "off",
|
|
|
|
indent: [
|
|
|
|
"error",
|
|
|
|
"tab",
|
|
|
|
{
|
|
|
|
|
|
|
|
// This makes it so code within the wrapper is not indented.
|
|
|
|
ignoredNodes: [
|
2023-09-19 16:58:24 +00:00
|
|
|
"Program > FunctionDeclaration > *"
|
2023-09-18 16:39:00 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
2023-09-19 16:58:24 +00:00
|
|
|
files: [
|
|
|
|
"src/wrapper.js",
|
|
|
|
"src/wrapper-factory.js"
|
|
|
|
],
|
2023-09-18 16:39:00 +00:00
|
|
|
languageOptions: {
|
2023-09-19 16:58:24 +00:00
|
|
|
sourceType: "script",
|
2023-09-18 16:39:00 +00:00
|
|
|
globals: {
|
2023-09-19 16:58:24 +00:00
|
|
|
module: false
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
2023-09-19 16:58:24 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [ "src/wrapper.js" ],
|
2023-09-18 16:39:00 +00:00
|
|
|
rules: {
|
|
|
|
indent: [
|
|
|
|
"error",
|
|
|
|
"tab",
|
|
|
|
{
|
|
|
|
|
|
|
|
// This makes it so code within the wrapper is not indented.
|
|
|
|
ignoredNodes: [
|
2023-09-19 16:58:24 +00:00
|
|
|
"Program > ExpressionStatement > CallExpression > :last-child > *"
|
2023-09-18 16:39:00 +00:00
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [ "src/exports/amd.js" ],
|
|
|
|
languageOptions: {
|
|
|
|
globals: {
|
|
|
|
define: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Tests
|
|
|
|
{
|
|
|
|
files: [
|
2024-06-06 13:56:44 +00:00
|
|
|
"test/*",
|
|
|
|
"test/data/**",
|
|
|
|
"test/integration/**",
|
|
|
|
"test/unit/**"
|
2023-09-18 16:39:00 +00:00
|
|
|
],
|
|
|
|
ignores: [
|
|
|
|
"test/data/badcall.js",
|
|
|
|
"test/data/badjson.js",
|
|
|
|
"test/data/support/csp.js",
|
|
|
|
"test/data/support/getComputedSupport.js",
|
|
|
|
"test/data/core/jquery-iterability-transpiled.js"
|
|
|
|
],
|
|
|
|
languageOptions: {
|
2024-06-06 13:56:44 +00:00
|
|
|
ecmaVersion: 2015,
|
|
|
|
sourceType: "script",
|
2023-09-18 16:39:00 +00:00
|
|
|
globals: {
|
|
|
|
...globals.browser,
|
|
|
|
require: false,
|
|
|
|
trustedTypes: false,
|
|
|
|
QUnit: false,
|
|
|
|
ajaxTest: false,
|
|
|
|
testIframe: false,
|
|
|
|
createDashboardXML: false,
|
|
|
|
createWithFriesXML: false,
|
|
|
|
createXMLFragment: false,
|
|
|
|
includesModule: false,
|
|
|
|
moduleTeardown: false,
|
|
|
|
url: false,
|
|
|
|
q: false,
|
2024-06-06 13:56:44 +00:00
|
|
|
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
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...jqueryConfig.rules,
|
|
|
|
|
2024-06-06 13:56:44 +00:00
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{ args: "after-used", argsIgnorePattern: "^_" }
|
|
|
|
],
|
2023-09-18 16:39:00 +00:00
|
|
|
|
|
|
|
// Too many errors
|
|
|
|
"max-len": "off",
|
2024-06-06 13:56:44 +00:00
|
|
|
camelcase: "off"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [
|
|
|
|
"test/unit/core.js"
|
|
|
|
],
|
|
|
|
rules: {
|
|
|
|
|
|
|
|
// Core has several cases where unused vars are expected
|
|
|
|
"no-unused-vars": "off"
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-03-05 19:44:01 +00:00
|
|
|
{
|
|
|
|
files: [
|
|
|
|
"test/runner/**/*.js"
|
|
|
|
],
|
|
|
|
languageOptions: {
|
2024-06-06 13:56:44 +00:00
|
|
|
ecmaVersion: "latest",
|
2024-03-05 19:44:01 +00:00
|
|
|
globals: {
|
|
|
|
...globals.node
|
2024-06-06 13:56:44 +00:00
|
|
|
}
|
2024-03-05 19:44:01 +00:00
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...jqueryConfig.rules
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [ "test/runner/listeners.js" ],
|
|
|
|
languageOptions: {
|
|
|
|
ecmaVersion: 5,
|
2024-06-06 13:56:44 +00:00
|
|
|
sourceType: "script",
|
|
|
|
globals: {
|
|
|
|
...globals.browser,
|
|
|
|
QUnit: false,
|
|
|
|
Symbol: false
|
|
|
|
}
|
2024-03-05 19:44:01 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2023-09-18 16:39:00 +00:00
|
|
|
{
|
|
|
|
files: [
|
2024-06-06 13:56:44 +00:00
|
|
|
"test/data/testinit.js",
|
2023-09-18 16:39:00 +00:00
|
|
|
"test/data/testrunner.js",
|
|
|
|
"test/data/core/jquery-iterability-transpiled-es6.js"
|
|
|
|
],
|
|
|
|
languageOptions: {
|
2024-06-06 13:56:44 +00:00
|
|
|
ecmaVersion: 2015,
|
|
|
|
sourceType: "script",
|
|
|
|
globals: {
|
|
|
|
...globals.browser
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...jqueryConfig.rules,
|
|
|
|
strict: [ "error", "function" ]
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [
|
2024-06-06 13:56:44 +00:00
|
|
|
"test/data/testinit.js"
|
2023-09-18 16:39:00 +00:00
|
|
|
],
|
|
|
|
rules: {
|
2024-06-06 13:56:44 +00:00
|
|
|
strict: [ "error", "global" ]
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [
|
2024-06-06 13:56:44 +00:00
|
|
|
"test/unit/deferred.js"
|
2023-09-18 16:39:00 +00:00
|
|
|
],
|
|
|
|
rules: {
|
2024-06-06 13:56:44 +00:00
|
|
|
|
|
|
|
// Deferred tests set strict mode for certain tests
|
|
|
|
strict: "off"
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [
|
2024-06-06 13:56:44 +00:00
|
|
|
"eslint.config.js",
|
2023-07-27 15:24:49 +00:00
|
|
|
".release-it.cjs",
|
|
|
|
"build/**",
|
2024-06-06 13:56:44 +00:00
|
|
|
"test/node_smoke_tests/**",
|
|
|
|
"test/bundler_smoke_tests/**/*",
|
|
|
|
"test/promises_aplus_adapters/**",
|
|
|
|
"test/middleware-mockserver.cjs"
|
2023-09-18 16:39:00 +00:00
|
|
|
],
|
|
|
|
languageOptions: {
|
2024-06-06 13:56:44 +00:00
|
|
|
ecmaVersion: "latest",
|
2023-09-18 16:39:00 +00:00
|
|
|
globals: {
|
2024-06-06 13:56:44 +00:00
|
|
|
...globals.browser,
|
|
|
|
...globals.node
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...jqueryConfig.rules,
|
2024-06-06 13:56:44 +00:00
|
|
|
"no-implicit-globals": "error",
|
2024-08-09 01:39:11 +00:00
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{ caughtErrorsIgnorePattern: "^_" }
|
|
|
|
],
|
2023-09-18 16:39:00 +00:00
|
|
|
strict: [ "error", "global" ]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
files: [
|
|
|
|
"dist/jquery.js",
|
|
|
|
"dist/jquery.slim.js",
|
2023-09-20 02:20:10 +00:00
|
|
|
"dist/jquery.factory.js",
|
|
|
|
"dist/jquery.factory.slim.js",
|
2023-09-18 16:39:00 +00:00
|
|
|
"dist-module/jquery.module.js",
|
2023-09-20 02:20:10 +00:00
|
|
|
"dist-module/jquery.slim.module.js",
|
|
|
|
"dist-module/jquery.factory.module.js",
|
2024-06-06 13:56:44 +00:00
|
|
|
"dist-module/jquery.factory.slim.module.js",
|
2023-07-27 15:24:49 +00:00
|
|
|
"dist/wrappers/*.js",
|
|
|
|
"dist-module/wrappers/*.js"
|
Core: Fix the exports setup to make bundlers work with ESM & CommonJS
We cannot pass a single file via the `module` condition as then
`require( "jquery" )` will not return jQuery but instead the module object
with `default`, `$` & `jQuery` as keys. Instead:
1. For Node.js, detected via the `node` condition:
1. Expose a regular CommonJS version to `require`
2. Expose a tiny wrapper over CommonJS to `import`
2. For bundlers, detected via the `module` condition:
1. Expose a regular ESM version to `import`
2. Expose a tiny wrapper over ESM to `require`
3. If neither Node.js nor bundlers are detected (no `node` or `module`
conditions`):
1. Expose a regular CommonJS version to `require`
2. Expose a regular ESM version to `import`
The reasons for such definitions are as follows:
1. In Node.js, one can synchronously import from a CommonJS file inside of
an ESM one but not vice-versa. To use an ESM file in a CommonJS one,
a dynamic import is required and that forces asynchronicity.
2. In some bundlers CommonJS is not necessarily enabled - e.g. in Rollup without
the CommonJS plugin. Therefore, the ESM version needs to be pure ESM.
However, bundlers allow synchronously calling `require` on an ESM file. This
is possible since bundlers merge the files before they are passed to
the browser to execute and the final bundles no longer contain async import
code.
3. Bare ESM & CommonJS versions are provided to non-Node non-bundler
environments where we cannot assume interoperability between ESM & CommonJS
is supported.
4. Bare versions cannot be supplied to Node or bundlers as projects using both
ESM & CommonJS to fetch jQuery would result in duplicate jQuery instances,
leading to increased JS size and disjoint data storage.
In addition to the above changes, the `script` condition has been dropped. Only
Webpack documents this condition and it's not clear when exactly it's triggered.
Adding support for a new condition can be added later without a breaking change;
removing is not so easy.
The `production` & `development` conditions have been removed as well. They were
not really applied correctly; we'd need to provide both of them to each current
leaf which would double the size of the definition for the `.` & `./slim` entry
points. In jQuery, the only difference between development & production builds
is minification; there are no logic changes so we can pass unminified versions
to all the tooling, expecting minification down the line.
As for the factory entry points:
1. Node.js always gets the CommonJS version
2. Bundlers always get the ESM version
3. Other tools take the ESM version when using `import` and the CommonJS when
using `require`.
The complexity is lower than for the `.` & `./slim` entry points because there's
no default export to handle so Node/bundler wrapper files are not necessary.
Other changes:
* Tests: Change "node:assert" to "node:assert/strict"; the former is deprecated
* Docs: Mention that the CommonJS module doesn't expose named exports
* Tests: Run Node & bundler tests for all the above cases
Fixes gh-5416
Closes gh-5429
2024-03-11 23:39:34 +00:00
|
|
|
],
|
|
|
|
languageOptions: {
|
2024-06-06 13:56:44 +00:00
|
|
|
ecmaVersion: 2015,
|
Core: Fix the exports setup to make bundlers work with ESM & CommonJS
We cannot pass a single file via the `module` condition as then
`require( "jquery" )` will not return jQuery but instead the module object
with `default`, `$` & `jQuery` as keys. Instead:
1. For Node.js, detected via the `node` condition:
1. Expose a regular CommonJS version to `require`
2. Expose a tiny wrapper over CommonJS to `import`
2. For bundlers, detected via the `module` condition:
1. Expose a regular ESM version to `import`
2. Expose a tiny wrapper over ESM to `require`
3. If neither Node.js nor bundlers are detected (no `node` or `module`
conditions`):
1. Expose a regular CommonJS version to `require`
2. Expose a regular ESM version to `import`
The reasons for such definitions are as follows:
1. In Node.js, one can synchronously import from a CommonJS file inside of
an ESM one but not vice-versa. To use an ESM file in a CommonJS one,
a dynamic import is required and that forces asynchronicity.
2. In some bundlers CommonJS is not necessarily enabled - e.g. in Rollup without
the CommonJS plugin. Therefore, the ESM version needs to be pure ESM.
However, bundlers allow synchronously calling `require` on an ESM file. This
is possible since bundlers merge the files before they are passed to
the browser to execute and the final bundles no longer contain async import
code.
3. Bare ESM & CommonJS versions are provided to non-Node non-bundler
environments where we cannot assume interoperability between ESM & CommonJS
is supported.
4. Bare versions cannot be supplied to Node or bundlers as projects using both
ESM & CommonJS to fetch jQuery would result in duplicate jQuery instances,
leading to increased JS size and disjoint data storage.
In addition to the above changes, the `script` condition has been dropped. Only
Webpack documents this condition and it's not clear when exactly it's triggered.
Adding support for a new condition can be added later without a breaking change;
removing is not so easy.
The `production` & `development` conditions have been removed as well. They were
not really applied correctly; we'd need to provide both of them to each current
leaf which would double the size of the definition for the `.` & `./slim` entry
points. In jQuery, the only difference between development & production builds
is minification; there are no logic changes so we can pass unminified versions
to all the tooling, expecting minification down the line.
As for the factory entry points:
1. Node.js always gets the CommonJS version
2. Bundlers always get the ESM version
3. Other tools take the ESM version when using `import` and the CommonJS when
using `require`.
The complexity is lower than for the `.` & `./slim` entry points because there's
no default export to handle so Node/bundler wrapper files are not necessary.
Other changes:
* Tests: Change "node:assert" to "node:assert/strict"; the former is deprecated
* Docs: Mention that the CommonJS module doesn't expose named exports
* Tests: Run Node & bundler tests for all the above cases
Fixes gh-5416
Closes gh-5429
2024-03-11 23:39:34 +00:00
|
|
|
globals: {
|
2023-09-18 16:39:00 +00:00
|
|
|
define: false,
|
|
|
|
module: false,
|
2024-06-06 13:56:44 +00:00
|
|
|
Symbol: false,
|
|
|
|
window: false
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...jqueryConfig.rules,
|
|
|
|
|
2024-06-06 13:56:44 +00:00
|
|
|
"no-implicit-globals": "error",
|
|
|
|
|
2023-09-18 16:39:00 +00:00
|
|
|
// That is okay for the built version
|
|
|
|
"no-multiple-empty-lines": "off",
|
|
|
|
|
2024-08-09 01:39:11 +00:00
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{ caughtErrorsIgnorePattern: "^_" }
|
|
|
|
],
|
|
|
|
|
2023-09-18 16:39:00 +00:00
|
|
|
// When custom compilation is used, the version string
|
|
|
|
// can get large. Accept that in the built version.
|
|
|
|
"max-len": "off",
|
|
|
|
"one-var": "off"
|
|
|
|
}
|
2024-06-06 13:56:44 +00:00
|
|
|
},
|
|
|
|
|
2024-06-15 13:11:34 +00:00
|
|
|
{
|
|
|
|
files: [
|
|
|
|
"dist/jquery.slim.js",
|
|
|
|
"dist/jquery.factory.slim.js",
|
|
|
|
"dist-module/jquery.slim.module.js",
|
|
|
|
"dist-module/jquery.factory.slim.module.js"
|
|
|
|
],
|
|
|
|
rules: {
|
|
|
|
|
|
|
|
// Rollup is now smart enough to remove the use
|
|
|
|
// of parameters if the argument is not passed
|
|
|
|
// anywhere in the build.
|
|
|
|
// The removal of effects in the slim build
|
|
|
|
// results in some parameters not being used,
|
|
|
|
// which can be safely ignored.
|
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
|
|
|
{ args: "none" }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2024-06-06 13:56:44 +00:00
|
|
|
{
|
|
|
|
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: [
|
2023-07-27 15:24:49 +00:00
|
|
|
"dist/wrappers/*.js"
|
2024-06-06 13:56:44 +00:00
|
|
|
],
|
|
|
|
languageOptions: {
|
|
|
|
ecmaVersion: 2015,
|
|
|
|
sourceType: "commonjs"
|
|
|
|
}
|
2023-09-18 16:39:00 +00:00
|
|
|
}
|
|
|
|
];
|