Build: Fix pre release matching in compare size regex
[jquery.git] / eslint.config.js
blob575c93fa4b0dec5f6f1a80cbee5dbb58c2c9dcb9
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                         "tmp",
14                         "test/data/json_obj.js",
15                         "test/data/jquery-*.js"
16                 ]
17         },
19         // Source
20         {
21                 files: [ "src/**" ],
22                 plugins: {
23                         import: importPlugin
24                 },
25                 languageOptions: {
26                         ecmaVersion: 2015,
28                         // The browser env is not enabled on purpose so that code takes
29                         // all browser-only globals from window instead of assuming
30                         // they're available as globals. This makes it possible to use
31                         // jQuery with tools like jsdom which provide a custom window
32                         // implementation.
33                         globals: {
34                                 window: false
35                         }
36                 },
37                 rules: {
38                         ...jqueryConfig.rules,
39                         "import/extensions": [ "error", "always" ],
40                         "import/no-cycle": "error",
42                         // TODO: Enable this rule when eslint-plugin-import supports
43                         // it when using flat config.
44                         // See https://github.com/import-js/eslint-plugin-import/issues/2556
46                         // "import/no-unused-modules": [
47                         //      "error",
48                         //      {
49                         //              unusedExports: true,
51                         //              // When run via WebStorm, the root path against which these paths
52                         //              // are resolved is the path where this ESLint config file lies,
53                         //              // i.e. `src`. When run via the command line, it's usually the root
54                         //              // folder of the jQuery repository. This pattern intends to catch both.
55                         //              // Note that we cannot specify two patterns here:
56                         //              //     [ "src/*.js", "*.js" ]
57                         //              // as they're analyzed individually and the rule crashes if a pattern
58                         //              // cannot be matched.
59                         //              ignoreExports: [ "{src/,}*.js" ]
60                         //      }
61                         // ],
62                         indent: [
63                                 "error",
64                                 "tab",
65                                 {
66                                         outerIIFEBody: 0
67                                 }
68                         ],
69                         "no-implicit-globals": "error",
70                         "no-unused-vars": [
71                                 "error",
72                                 { caughtErrorsIgnorePattern: "^_" }
73                         ],
74                         "one-var": [ "error", { var: "always" } ],
75                         strict: [ "error", "function" ]
76                 }
77         },
79         {
80                 files: [
81                         "src/wrapper.js",
82                         "src/wrapper-esm.js",
83                         "src/wrapper-factory.js",
84                         "src/wrapper-factory-esm.js"
85                 ],
86                 languageOptions: {
87                         globals: {
88                                 jQuery: false
89                         }
90                 },
91                 rules: {
92                         "no-unused-vars": "off",
93                         indent: [
94                                 "error",
95                                 "tab",
96                                 {
98                                         // This makes it so code within the wrapper is not indented.
99                                         ignoredNodes: [
100                                                 "Program > FunctionDeclaration > *"
101                                         ]
102                                 }
103                         ]
104                 }
105         },
107         {
108                 files: [
109                         "src/wrapper.js",
110                         "src/wrapper-factory.js"
111                 ],
112                 languageOptions: {
113                         sourceType: "script",
114                         globals: {
115                                 module: false
116                         }
117                 }
118         },
120         {
121                 files: [ "src/wrapper.js" ],
122                 rules: {
123                         indent: [
124                                 "error",
125                                 "tab",
126                                 {
128                                         // This makes it so code within the wrapper is not indented.
129                                         ignoredNodes: [
130                                                 "Program > ExpressionStatement > CallExpression > :last-child > *"
131                                         ]
132                                 }
133                         ]
134                 }
135         },
137         {
138                 files: [ "src/exports/amd.js" ],
139                 languageOptions: {
140                         globals: {
141                                 define: false
142                         }
143                 }
144         },
146         // Tests
147         {
148                 files: [
149                         "test/*",
150                         "test/data/**",
151                         "test/integration/**",
152                         "test/unit/**"
153                 ],
154                 ignores: [
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                         ecmaVersion: 5,
163                         sourceType: "script",
164                         globals: {
165                                 ...globals.browser,
166                                 require: false,
167                                 Promise: false,
168                                 Symbol: false,
169                                 trustedTypes: false,
170                                 QUnit: false,
171                                 ajaxTest: false,
172                                 testIframe: false,
173                                 createDashboardXML: false,
174                                 createWithFriesXML: false,
175                                 createXMLFragment: false,
176                                 includesModule: false,
177                                 moduleTeardown: false,
178                                 url: false,
179                                 q: false,
180                                 jQuery: false,
181                                 $: false,
182                                 sinon: false,
183                                 amdDefined: false,
184                                 fireNative: false,
185                                 Globals: false,
186                                 hasPHP: false,
187                                 isLocal: false,
188                                 supportjQuery: false,
189                                 originaljQuery: false,
190                                 original$: false,
191                                 baseURL: false,
192                                 externalHost: false
193                         }
194                 },
195                 rules: {
196                         ...jqueryConfig.rules,
198                         "no-unused-vars": [
199                                 "error",
200                                 { args: "after-used", argsIgnorePattern: "^_" }
201                         ],
203                         // Too many errors
204                         "max-len": "off",
205                         camelcase: "off"
206                 }
207         },
209         {
210                 files: [
211                         "test/unit/core.js"
212                 ],
213                 rules: {
215                         // Core has several cases where unused vars are expected
216                         "no-unused-vars": "off"
217                 }
218         },
220         {
221                 files: [
222                         "test/runner/**/*.js"
223                 ],
224                 languageOptions: {
225                         ecmaVersion: "latest",
226                         globals: {
227                                 ...globals.node
228                         }
229                 },
230                 rules: {
231                         ...jqueryConfig.rules
232                 }
233         },
235         {
236                 files: [ "test/runner/listeners.js" ],
237                 languageOptions: {
238                         ecmaVersion: 5,
239                         sourceType: "script",
240                         globals: {
241                                 ...globals.browser,
242                                 QUnit: false,
243                                 Symbol: false
244                         }
245                 }
246         },
248         {
249                 files: [
250                         "test/data/testinit.js",
251                         "test/data/testrunner.js",
252                         "test/data/core/jquery-iterability-transpiled-es6.js"
253                 ],
254                 languageOptions: {
255                         ecmaVersion: 2015,
256                         sourceType: "script",
257                         globals: {
258                                 ...globals.browser
259                         }
260                 },
261                 rules: {
262                         ...jqueryConfig.rules,
263                         strict: [ "error", "function" ]
264                 }
265         },
267         {
268                 files: [
269                         "test/data/testinit.js"
270                 ],
271                 rules: {
272                         strict: [ "error", "global" ]
273                 }
274         },
276         {
277                 files: [
278                         "test/unit/deferred.js"
279                 ],
280                 rules: {
282                         // Deferred tests set strict mode for certain tests
283                         strict: "off"
284                 }
285         },
287         {
288                 files: [
289                         "eslint.config.js",
290                         ".release-it.cjs",
291                         "build/**",
292                         "test/node_smoke_tests/**",
293                         "test/bundler_smoke_tests/**/*",
294                         "test/promises_aplus_adapters/**",
295                         "test/middleware-mockserver.cjs"
296                 ],
297                 languageOptions: {
298                         ecmaVersion: "latest",
299                         globals: {
300                                 ...globals.browser,
301                                 ...globals.node
302                         }
303                 },
304                 rules: {
305                         ...jqueryConfig.rules,
306                         "no-implicit-globals": "error",
307                         "no-unused-vars": [
308                                 "error",
309                                 { caughtErrorsIgnorePattern: "^_" }
310                         ],
311                         strict: [ "error", "global" ]
312                 }
313         },
315         {
316                 files: [
317                         "dist/jquery.js",
318                         "dist/jquery.slim.js",
319                         "dist/jquery.factory.js",
320                         "dist/jquery.factory.slim.js",
321                         "dist-module/jquery.module.js",
322                         "dist-module/jquery.slim.module.js",
323                         "dist-module/jquery.factory.module.js",
324                         "dist-module/jquery.factory.slim.module.js",
325                         "dist/wrappers/*.js",
326                         "dist-module/wrappers/*.js"
327                 ],
328                 languageOptions: {
329                         ecmaVersion: 2015,
330                         globals: {
331                                 define: false,
332                                 module: false,
333                                 Symbol: false,
334                                 window: false
335                         }
336                 },
337                 rules: {
338                         ...jqueryConfig.rules,
340                         "no-implicit-globals": "error",
342                         // That is okay for the built version
343                         "no-multiple-empty-lines": "off",
345                         "no-unused-vars": [
346                                 "error",
347                                 { caughtErrorsIgnorePattern: "^_" }
348                         ],
350                         // When custom compilation is used, the version string
351                         // can get large. Accept that in the built version.
352                         "max-len": "off",
353                         "one-var": "off"
354                 }
355         },
357         {
358                 files: [
359                         "dist/jquery.slim.js",
360                         "dist/jquery.factory.slim.js",
361                         "dist-module/jquery.slim.module.js",
362                         "dist-module/jquery.factory.slim.module.js"
363                 ],
364                 rules: {
366                         // Rollup is now smart enough to remove the use
367                         // of parameters if the argument is not passed
368                         // anywhere in the build.
369                         // The removal of effects in the slim build
370                         // results in some parameters not being used,
371                         // which can be safely ignored.
372                         "no-unused-vars": [
373                                 "error",
374                                 { args: "none" }
375                         ]
376                 }
377         },
379         {
380                 files: [
381                         "src/wrapper.js",
382                         "src/wrapper-factory.js",
383                         "dist/jquery.factory.js",
384                         "dist/jquery.factory.slim.js",
385                         "test/middleware-mockserver.cjs"
386                 ],
387                 rules: {
388                         "no-implicit-globals": "off"
389                 }
390         },
392         {
393                 files: [
394                         "dist/**"
395                 ],
396                 languageOptions: {
397                         ecmaVersion: 5,
398                         sourceType: "script"
399                 }
400         },
402         {
403                 files: [
404                         "dist-module/**"
405                 ],
406                 languageOptions: {
407                         ecmaVersion: 2015,
408                         sourceType: "module"
409                 }
410         },
412         {
413                 files: [
414                         "dist/wrappers/*.js"
415                 ],
416                 languageOptions: {
417                         ecmaVersion: 2015,
418                         sourceType: "commonjs"
419                 }
420         }