Build: Reformat GitHub workflow Yaml files
[jquery.git] / eslint.config.js
blob8b0b0f4a549207b183b5074c3972230c195310b1
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: [
93                         "src/wrapper.js",
94                         "src/wrapper-esm.js",
95                         "src/wrapper-factory.js",
96                         "src/wrapper-factory-esm.js"
97                 ],
98                 languageOptions: {
99                         globals: {
100                                 jQuery: false
101                         }
102                 },
103                 rules: {
104                         "no-unused-vars": "off",
105                         indent: [
106                                 "error",
107                                 "tab",
108                                 {
110                                         // This makes it so code within the wrapper is not indented.
111                                         ignoredNodes: [
112                                                 "Program > FunctionDeclaration > *"
113                                         ]
114                                 }
115                         ]
116                 }
117         },
119         {
120                 files: [
121                         "src/wrapper.js",
122                         "src/wrapper-factory.js"
123                 ],
124                 languageOptions: {
125                         sourceType: "script",
126                         globals: {
127                                 module: false
128                         }
129                 }
130         },
132         {
133                 files: [ "src/wrapper.js" ],
134                 rules: {
135                         indent: [
136                                 "error",
137                                 "tab",
138                                 {
140                                         // This makes it so code within the wrapper is not indented.
141                                         ignoredNodes: [
142                                                 "Program > ExpressionStatement > CallExpression > :last-child > *"
143                                         ]
144                                 }
145                         ]
146                 }
147         },
149         {
150                 files: [ "src/exports/amd.js" ],
151                 languageOptions: {
152                         globals: {
153                                 define: false
154                         }
155                 }
156         },
158         // Tests
159         {
160                 files: [
161                         "test/**"
162                 ],
163                 ignores: [
164                         "test/data/jquery-1.9.1.js",
165                         "test/data/badcall.js",
166                         "test/data/badjson.js",
167                         "test/data/support/csp.js",
168                         "test/data/support/getComputedSupport.js",
169                         "test/data/core/jquery-iterability-transpiled.js"
170                 ],
171                 languageOptions: {
172                         globals: {
173                                 ...globals.browser,
174                                 require: false,
175                                 Promise: false,
176                                 Symbol: false,
177                                 trustedTypes: false,
178                                 QUnit: false,
179                                 ajaxTest: false,
180                                 testIframe: false,
181                                 createDashboardXML: false,
182                                 createWithFriesXML: false,
183                                 createXMLFragment: false,
184                                 includesModule: false,
185                                 moduleTeardown: false,
186                                 url: false,
187                                 q: false,
188                                 jQuery: true,
189                                 sinon: true,
190                                 amdDefined: true,
191                                 fireNative: true,
192                                 Globals: true,
193                                 hasPHP: true,
194                                 isLocal: true,
195                                 supportjQuery: true,
196                                 originaljQuery: true,
197                                 $: true,
198                                 original$: true,
199                                 baseURL: true,
200                                 externalHost: true
201                         }
202                 },
203                 rules: {
204                         ...jqueryConfig.rules,
205                         strict: [ "error", "function" ],
207                         // See https://github.com/eslint/eslint/issues/2342
208                         "no-unused-vars": "off",
210                         // Too many errors
211                         "max-len": "off",
212                         camelcase: "off",
213                         "one-var": "off"
214                 }
215         },
217         {
218                 files: [
219                         "test/data/testrunner.js",
220                         "test/data/core/jquery-iterability-transpiled-es6.js"
221                 ],
222                 languageOptions: {
223                         sourceType: "script"
224                 }
225         },
227         {
228                 files: [
229                         "test/unit/deferred.js"
230                 ],
231                 rules: {
233                         // Deferred tests set strict mode for certain tests
234                         strict: "off"
235                 }
236         },
238         {
239                 files: [
240                         "test/node_smoke_tests/commonjs/**",
241                         "test/node_smoke_tests/module/**",
242                         "test/promises_aplus_adapters/**",
243                         "test/middleware-mockserver.cjs"
244                 ],
245                 languageOptions: {
246                         globals: {
247                                 ...globals.node,
248                                 ...globals.es2021
249                         }
250                 },
251                 rules: {
252                         strict: [ "error", "global" ]
253                 }
254         },
256         {
257                 files: [
258                         "build/**",
259                         "test/data/testinit.js",
260                         "test/data/testinit-jsdom.js"
261                 ],
262                 languageOptions: {
263                         globals: {
264                                 ...globals.node,
265                                 ...globals.es2021
266                         }
267                 },
268                 rules: {
269                         ...jqueryConfig.rules,
270                         strict: [ "error", "global" ]
271                 }
272         },
274         {
275                 files: [
276                         "build/**/*.js",
277                         "test/data/testinit.js",
278                         "test/data/testinit-jsdom.js"
279                 ],
280                 languageOptions: {
281                         sourceType: "commonjs"
282                 }
283         },
285         {
286                 files: [
287                         "dist/jquery.js",
288                         "dist/jquery.slim.js",
289                         "dist/jquery.factory.js",
290                         "dist/jquery.factory.slim.js",
291                         "dist-module/jquery.module.js",
292                         "dist-module/jquery.slim.module.js",
293                         "dist-module/jquery.factory.module.js",
294                         "dist-module/jquery.factory.slim.module.js"
295                 ],
297                 languageOptions: {
298                         globals: {
299                                 ...globals.browser,
300                                 ...globals.es2021,
301                                 define: false,
302                                 module: false,
303                                 Symbol: false
304                         }
305                 },
307                 rules: {
308                         ...jqueryConfig.rules,
310                         // That is okay for the built version
311                         "no-multiple-empty-lines": "off",
313                         // When custom compilation is used, the version string
314                         // can get large. Accept that in the built version.
315                         "max-len": "off",
316                         "one-var": "off"
317                 }
318         }