3 const xpcshellTestConfig = require("eslint-plugin-mozilla/lib/configs/xpcshell-test.js");
4 const browserTestConfig = require("eslint-plugin-mozilla/lib/configs/browser-test.js");
5 const mochitestTestConfig = require("eslint-plugin-mozilla/lib/configs/mochitest-test.js");
6 const chromeTestConfig = require("eslint-plugin-mozilla/lib/configs/chrome-test.js");
9 * Some configurations have overrides, which can't be specified within overrides,
10 * so we need to remove them.
12 function removeOverrides(config) {
14 delete config.overrides;
18 const xpcshellTestPaths = [
23 const browserTestPaths = [
24 "**/test*/**/browser/",
27 const mochitestTestPaths = [
28 "**/test*/mochitest/",
31 const chromeTestPaths = [
36 // New rules and configurations should generally be added in
37 // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
38 // allow external repositories that use the plugin to pick them up as well.
40 "plugin:mozilla/recommended"
45 // The html plugin is enabled via a command line option on eslint. To avoid
46 // bad interactions with the xml preprocessor in eslint-plugin-mozilla, we
47 // turn off processing of the html plugin for .xml files.
49 "html/xml-extensions": [ ".xhtml" ]
53 // eslint-plugin-html handles eol-last slightly different - it applies to
54 // each set of script tags, so we turn it off here.
55 "files": "**/*.*html",
60 // These xbl bindings are assumed to be in the browser-window environment,
61 // we would mark it in the files, but ESLint made this more difficult with
62 // our xml processor, so we list them here. Bug 1397874 & co are working
63 // towards removing these files completely.
65 "browser/base/content/tabbrowser.xml",
66 "browser/base/content/urlbarBindings.xml",
67 "browser/components/search/content/search.xml",
68 "browser/components/translation/translation-infobar.xml",
69 "toolkit/components/prompts/content/tabprompts.xml"
72 "mozilla/browser-window": true
75 // TODO: Bug 1515949. Enable no-undef for gfx/
76 "files": "gfx/layers/apz/test/mochitest/**",
81 ...removeOverrides(xpcshellTestConfig),
82 "files": xpcshellTestPaths.map(path => `${path}**`),
83 "excludedFiles": "devtools/**"
85 // If it is an xpcshell head file, we turn off global unused variable checks, as it
86 // would require searching the other test files to know if they are used or not.
87 // This would be expensive and slow, and it isn't worth it for head files.
88 // We could get developers to declare as exported, but that doesn't seem worth it.
89 "files": xpcshellTestPaths.map(path => `${path}head*.js`),
92 "no-unused-vars": ["error", {
99 "files": browserTestPaths.map(path => `${path}**`),
100 "excludedFiles": "devtools/**"
102 ...removeOverrides(mochitestTestConfig),
103 "files": mochitestTestPaths.map(path => `${path}**`),
106 "security/manager/ssl/tests/mochitest/browser/**",
107 "testing/mochitest/**",
110 ...removeOverrides(chromeTestConfig),
111 "files": chromeTestPaths.map(path => `${path}**`),
117 // Ideally we wouldn't be using the simpletest env here, but our uses of
118 // js files mean we pick up everything from the global scope, which could
119 // be any one of a number of html files. So we just allow the basics...
120 "mozilla/simpletest": true,
123 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
124 ...chromeTestPaths.map(path => `${path}/**/*.js`),
128 "extensions/permissions/test/**",
129 "extensions/spellcheck/**",
130 "extensions/universalchardet/tests/**",
133 "mozilla/reject-importGlobalProperties": "off",
134 "mozilla/use-default-preference-values": "off",
135 "mozilla/use-services": "off",
136 "no-array-constructor": "off",
138 "no-unused-vars": "off",
139 "no-redeclare": "off",
140 "no-global-assign": "off",
142 // Not enabling the rules below for now pending prettier roll-out.
143 "brace-style": "off",
144 "comma-dangle": "off",
145 "linebreak-style": "off",
147 "no-mixed-spaces-and-tabs": "off",
148 "no-multi-spaces": "off",
149 "no-trailing-spaces": "off",
150 "padded-blocks": "off",
153 "space-infix-ops": "off",
160 "mozilla/consistent-if-bracing": "off",
161 "mozilla/use-chromeutils-generateqi": "off",
162 "mozilla/use-services": "off",
163 "no-array-constructor": "off",
164 "no-implied-eval": "off",
165 "no-redeclare": "off",
166 "no-self-assign": "off",
167 "no-throw-literal": "off",
169 "no-unneeded-ternary": "off",
170 "no-unused-vars": "off",
172 // Not enabling the rules below for now pending prettier roll-out.
173 "brace-style": "off",
174 "comma-dangle": "off",
175 "comma-spacing": "off",
176 "key-spacing": "off",
177 "keyword-spacing": "off",
178 "no-extra-semi": "off",
180 "no-mixed-spaces-and-tabs": "off",
181 "no-multi-spaces": "off",
182 "no-trailing-spaces": "off",
183 "padded-blocks": "off",
186 "space-before-function-paren": "off",
187 "space-infix-ops": "off",
191 "netwerk/cookie/test/browser/**",
192 "netwerk/test/browser/**",
193 "netwerk/test/mochitests/**",
194 "netwerk/test/unit*/**",
197 "object-shorthand": "off",
198 "mozilla/consistent-if-bracing": "off",
199 "mozilla/reject-importGlobalProperties": "off",
200 "mozilla/no-arbitrary-setTimeout": "off",
201 "mozilla/no-define-cc-etc": "off",
202 "mozilla/no-useless-parameters": "off",
203 "mozilla/no-useless-run-test": "off",
204 "mozilla/use-chromeutils-generateqi": "off",
205 "mozilla/use-chromeutils-import": "off",
206 "mozilla/use-default-preference-values": "off",
207 "mozilla/use-services": "off",
208 "consistent-return": "off",
209 "no-array-constructor": "off",
210 "no-extra-boolean-cast": "off",
212 "no-else-return": "off",
213 "no-global-assign": "off",
214 "no-lonely-if": "off",
215 "no-nested-ternary": "off",
216 "no-new-wrappers": "off",
217 "no-redeclare": "off",
218 "no-return-await": "off",
219 "no-sequences": "off",
221 "no-throw-literal": "off",
223 "no-unreachable": "off",
224 "no-unused-vars": "off",
225 "no-useless-return": "off",
227 // Not enabling the rules below for now pending prettier roll-out.
228 "arrow-spacing": "off",
229 "block-spacing": "off",
230 "brace-style": "off",
231 "comma-dangle": "off",
232 "comma-spacing": "off",
233 "comma-style": "off",
235 "func-call-spacing": "off",
236 "generator-star-spacing": "off",
237 "key-spacing": "off",
238 "keyword-spacing": "off",
239 "no-extra-semi": "off",
241 "no-mixed-spaces-and-tabs": "off",
242 "no-multi-spaces": "off",
243 "no-trailing-spaces": "off",
244 "no-whitespace-before-property": "off",
245 "padded-blocks": "off",
247 "rest-spread-spacing": "off",
249 "space-before-blocks": "off",
250 "space-before-function-paren": "off",
251 "space-infix-ops": "off",
252 "space-unary-ops": "off",
253 "spaced-comment": "off",
260 "object-shorthand": "off",
261 "mozilla/avoid-removeChild": "off",
262 "mozilla/consistent-if-bracing": "off",
263 "mozilla/reject-importGlobalProperties": "off",
264 "mozilla/no-arbitrary-setTimeout": "off",
265 "mozilla/no-define-cc-etc": "off",
266 "mozilla/no-useless-parameters": "off",
267 "mozilla/no-useless-run-test": "off",
268 "mozilla/use-chromeutils-generateqi": "off",
269 "mozilla/use-chromeutils-import": "off",
270 "mozilla/use-default-preference-values": "off",
271 "mozilla/use-includes-instead-of-indexOf": "off",
272 "mozilla/use-services": "off",
273 "mozilla/use-ownerGlobal": "off",
275 "consistent-return": "off",
276 "dot-notation": "off",
277 "no-array-constructor": "off",
279 "no-cond-assign": "off",
280 "no-extra-boolean-cast": "off",
282 "no-else-return": "off",
283 "no-func-assign": "off",
284 "no-global-assign": "off",
285 "no-implied-eval": "off",
286 "no-lonely-if": "off",
287 "no-nested-ternary": "off",
288 "no-new-wrappers": "off",
289 "no-redeclare": "off",
290 "no-restricted-globals": "off",
291 "no-return-await": "off",
292 "no-sequences": "off",
293 "no-throw-literal": "off",
294 "no-useless-concat": "off",
296 "no-unreachable": "off",
297 "no-unsanitized/method": "off",
298 "no-unsanitized/property": "off",
299 "no-unsafe-negation": "off",
300 "no-unused-vars": "off",
301 "no-useless-return": "off",
303 // Not enabling the rules below for now pending prettier roll-out.
304 "arrow-spacing": "off",
305 "block-spacing": "off",
306 "brace-style": "off",
307 "comma-dangle": "off",
308 "comma-spacing": "off",
309 "comma-style": "off",
311 "func-call-spacing": "off",
312 "generator-star-spacing": "off",
313 "linebreak-style": "off",
314 "key-spacing": "off",
315 "keyword-spacing": "off",
316 "no-extra-semi": "off",
318 "no-mixed-spaces-and-tabs": "off",
319 "no-multi-spaces": "off",
320 "no-trailing-spaces": "off",
321 "no-unexpected-multiline": "off",
322 "no-whitespace-before-property": "off",
323 "padded-blocks": "off",
325 "rest-spread-spacing": "off",
327 "space-before-blocks": "off",
328 "space-before-function-paren": "off",
329 "space-infix-ops": "off",
330 "space-unary-ops": "off",
331 "spaced-comment": "off",
337 "dom/base/test/unit/test_serializers_entities*.js",
338 "dom/base/test/unit_ipc/**",
339 "dom/base/test/jsmodules/**",
348 "dom/media/tests/**",
349 "dom/media/webaudio/**",
350 "dom/media/webspeech/**",
351 "dom/messagechannel/**",
355 "dom/performance/**",
358 "dom/security/test/cors/**",
359 "dom/security/test/csp/**",
360 "dom/security/test/general/**",
361 "dom/security/test/mixedcontentblocker/**",
362 "dom/security/test/sri/**",
363 "dom/serviceworkers/**",
365 "dom/tests/mochitest/**",
379 "consistent-return": "off",
380 "dot-notation": "off",
381 "object-shorthand": "off",
382 "mozilla/avoid-removeChild": "off",
383 "mozilla/consistent-if-bracing": "off",
384 "mozilla/no-arbitrary-setTimeout": "off",
385 "mozilla/no-compare-against-boolean-literals": "off",
386 "mozilla/no-define-cc-etc": "off",
387 "mozilla/no-useless-parameters": "off",
388 "mozilla/no-useless-run-test": "off",
389 "mozilla/reject-importGlobalProperties": "off",
390 "mozilla/use-cc-etc": "off",
391 "mozilla/use-chromeutils-generateqi": "off",
392 "mozilla/use-chromeutils-import": "off",
393 "mozilla/use-includes-instead-of-indexOf": "off",
394 "mozilla/use-ownerGlobal": "off",
395 "mozilla/use-services": "off",
396 "no-array-constructor": "off",
398 "no-cond-assign": "off",
399 "no-control-regex": "off",
400 "no-debugger": "off",
401 "no-else-return": "off",
404 "no-extra-boolean-cast": "off",
405 "no-func-assign": "off",
406 "no-global-assign": "off",
407 "no-implied-eval": "off",
408 "no-lone-blocks": "off",
409 "no-lonely-if": "off",
410 "no-nested-ternary": "off",
411 "no-new-object": "off",
412 "no-new-wrappers": "off",
414 "no-redeclare": "off",
415 "no-return-await": "off",
416 "no-restricted-globals": "off",
417 "no-self-assign": "off",
418 "no-self-compare": "off",
419 "no-sequences": "off",
421 "no-shadow-restricted-names": "off",
422 "no-sparse-arrays": "off",
423 "no-throw-literal": "off",
424 "no-unneeded-ternary": "off",
425 "no-unreachable": "off",
426 "no-unsanitized/method": "off",
427 "no-unsanitized/property": "off",
429 "no-unused-vars": "off",
430 "no-useless-call": "off",
431 "no-useless-concat": "off",
432 "no-useless-return": "off",
435 // Not enabling the rules below for now pending prettier roll-out.
436 "arrow-spacing": "off",
437 "block-spacing": "off",
438 "brace-style": "off",
439 "comma-dangle": "off",
440 "comma-spacing": "off",
441 "comma-style": "off",
442 "computed-property-spacing": "off",
444 "func-call-spacing": "off",
445 "generator-star-spacing": "off",
446 "linebreak-style": "off",
447 "key-spacing": "off",
448 "keyword-spacing": "off",
449 "no-extra-semi": "off",
451 "no-mixed-spaces-and-tabs": "off",
452 "no-multi-spaces": "off",
453 "no-trailing-spaces": "off",
454 "no-unexpected-multiline": "off",
455 "no-whitespace-before-property": "off",
456 "padded-blocks": "off",
458 "rest-spread-spacing": "off",
460 "space-before-blocks": "off",
461 "space-before-function-paren": "off",
462 "space-infix-ops": "off",
463 "space-unary-ops": "off",
464 "spaced-comment": "off",