Build: migrate most grunt tasks off of grunt
[jquery.git] / eslint.config.js
blob4c8d86bbdebd5fb4197996a6c9913563fb67f9ea
1 import jqueryConfig from "eslint-config-jquery";
2 import importPlugin from "eslint-plugin-import";
3 import globals from "globals";
5 export default [
6         {
8                 // Only global ignores will bypass the parser
9                 // and avoid JS parsing errors
10                 // See https://github.com/eslint/eslint/discussions/17412
11                 ignores: [
12                         "external",
13                         "test/data/json_obj.js"
14                 ]
15         },
17         {
18                 files: [
19                         "eslint.config.js",
20                         "Gruntfile.cjs",
21                         "test/node_smoke_tests/commonjs/**",
22                         "test/node_smoke_tests/module/**",
23                         "test/promises_aplus_adapters/**",
24                         "test/middleware-mockserver.cjs"
25                 ],
26                 languageOptions: {
27                         globals: {
28                                 ...globals.node
29                         }
30                 },
31                 rules: {
32                         ...jqueryConfig.rules,
33                         strict: [ "error", "global" ]
34                 }
35         },
37         // Source
38         {
39                 files: [ "src/**" ],
40                 plugins: {
41                         import: importPlugin
42                 },
43                 languageOptions: {
45                         // The browser env is not enabled on purpose so that code takes
46                         // all browser-only globals from window instead of assuming
47                         // they're available as globals. This makes it possible to use
48                         // jQuery with tools like jsdom which provide a custom window
49                         // implementation.
50                         globals: {
51                                 window: false
52                         }
53                 },
54                 rules: {
55                         ...jqueryConfig.rules,
56                         "import/extensions": [ "error", "always" ],
57                         "import/no-cycle": "error",
59                         // TODO: Enable this rule when eslint-plugin-import supports
60                         // it when using flat config.
61                         // See https://github.com/import-js/eslint-plugin-import/issues/2556
63                         // "import/no-unused-modules": [
64                         //      "error",
65                         //      {
66                         //              unusedExports: true,
68                         //              // When run via WebStorm, the root path against which these paths
69                         //              // are resolved is the path where this ESLint config file lies,
70                         //              // i.e. `src`. When run via the command line, it's usually the root
71                         //              // folder of the jQuery repository. This pattern intends to catch both.
72                         //              // Note that we cannot specify two patterns here:
73                         //              //     [ "src/*.js", "*.js" ]
74                         //              // as they're analyzed individually and the rule crashes if a pattern
75                         //              // cannot be matched.
76                         //              ignoreExports: [ "{src/,}*.js" ]
77                         //      }
78                         // ],
79                         indent: [
80                                 "error",
81                                 "tab",
82                                 {
83                                         outerIIFEBody: 0
84                                 }
85                         ],
86                         "one-var": [ "error", { var: "always" } ],
87                         strict: [ "error", "function" ]
88                 }
89         },
91         {
92                 files: [ "src/wrapper.js" ],
93                 languageOptions: {
94                         sourceType: "script",
95                         globals: {
96                                 jQuery: false,
97                                 module: true
98                         }
99                 },
100                 rules: {
101                         "no-unused-vars": "off",
102                         indent: [
103                                 "error",
104                                 "tab",
105                                 {
107                                         // This makes it so code within the wrapper is not indented.
108                                         ignoredNodes: [
109                                                 "Program > ExpressionStatement > CallExpression > :last-child > *"
110                                         ]
111                                 }
112                         ]
113                 }
114         },
116         {
117                 files: [ "src/wrapper-esm.js" ],
118                 languageOptions: {
119                         globals: {
120                                 jQuery: false
121                         }
122                 },
123                 rules: {
124                         "no-unused-vars": "off",
125                         indent: [
126                                 "error",
127                                 "tab",
128                                 {
130                                         // This makes it so code within the wrapper is not indented.
131                                         ignoredNodes: [
132                                                 "Program > FunctionDeclaration > *"
133                                         ]
134                                 }
135                         ]
136                 }
137         },
139         {
140                 files: [ "src/exports/amd.js" ],
141                 languageOptions: {
142                         globals: {
143                                 define: false
144                         }
145                 }
146         },
148         // Tests
149         {
150                 files: [
151                         "test/**"
152                 ],
153                 ignores: [
154                         "test/data/jquery-1.9.1.js",
155                         "test/data/badcall.js",
156                         "test/data/badjson.js",
157                         "test/data/support/csp.js",
158                         "test/data/support/getComputedSupport.js",
159                         "test/data/core/jquery-iterability-transpiled.js"
160                 ],
161                 languageOptions: {
162                         globals: {
163                                 ...globals.browser,
164                                 require: false,
165                                 Promise: false,
166                                 Symbol: false,
167                                 trustedTypes: false,
168                                 QUnit: false,
169                                 ajaxTest: false,
170                                 testIframe: false,
171                                 createDashboardXML: false,
172                                 createWithFriesXML: false,
173                                 createXMLFragment: false,
174                                 includesModule: false,
175                                 moduleTeardown: false,
176                                 url: false,
177                                 q: false,
178                                 jQuery: true,
179                                 sinon: true,
180                                 amdDefined: true,
181                                 fireNative: true,
182                                 Globals: true,
183                                 hasPHP: true,
184                                 isLocal: true,
185                                 supportjQuery: true,
186                                 originaljQuery: true,
187                                 $: true,
188                                 original$: true,
189                                 baseURL: true,
190                                 externalHost: true
191                         }
192                 },
193                 rules: {
194                         ...jqueryConfig.rules,
195                         strict: [ "error", "function" ],
197                         // See https://github.com/eslint/eslint/issues/2342
198                         "no-unused-vars": "off",
200                         // Too many errors
201                         "max-len": "off",
202                         camelcase: "off",
203                         "one-var": "off"
204                 }
205         },
207         {
208                 files: [
209                         "test/data/testrunner.js",
210                         "test/data/core/jquery-iterability-transpiled-es6.js"
211                 ],
212                 languageOptions: {
213                         sourceType: "script"
214                 }
215         },
217         {
218                 files: [
219                         "test/unit/deferred.js"
220                 ],
221                 rules: {
223                         // Deferred tests set strict mode for certain tests
224                         strict: "off"
225                 }
226         },
228         {
229                 files: [
230                         "test/node_smoke_tests/commonjs/**",
231                         "test/node_smoke_tests/module/**",
232                         "test/promises_aplus_adapters/**",
233                         "test/middleware-mockserver.cjs"
234                 ],
235                 languageOptions: {
236                         globals: {
237                                 ...globals.node,
238                                 ...globals.es2021
239                         }
240                 },
241                 rules: {
242                         strict: [ "error", "global" ]
243                 }
244         },
246         {
247                 files: [
248                         "build/**",
249                         "test/data/testinit.js",
250                         "test/data/testinit-jsdom.js"
251                 ],
252                 languageOptions: {
253                         globals: {
254                                 ...globals.node,
255                                 ...globals.es2021
256                         }
257                 },
258                 rules: {
259                         ...jqueryConfig.rules,
260                         strict: [ "error", "global" ]
261                 }
262         },
264         {
265                 files: [
266                         "build/**/*.js",
267                         "test/data/testinit.js",
268                         "test/data/testinit-jsdom.js"
269                 ],
270                 languageOptions: {
271                         sourceType: "commonjs"
272                 }
273         },
275         {
276                 files: [
277                         "dist/jquery.js",
278                         "dist/jquery.slim.js",
279                         "dist-module/jquery.module.js",
280                         "dist-module/jquery.slim.module.js"
281                 ],
283                 languageOptions: {
284                         globals: {
285                                 ...globals.browser,
286                                 ...globals.es2021,
287                                 define: false,
288                                 module: false,
289                                 Symbol: false
290                         }
291                 },
293                 rules: {
294                         ...jqueryConfig.rules,
296                         // That is okay for the built version
297                         "no-multiple-empty-lines": "off",
299                         // When custom compilation is used, the version string
300                         // can get large. Accept that in the built version.
301                         "max-len": "off",
302                         "one-var": "off"
303                 }
304         }