1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 const xpcshellTestConfig = require("eslint-plugin-mozilla/lib/configs/xpcshell-test.js");
8 const browserTestConfig = require("eslint-plugin-mozilla/lib/configs/browser-test.js");
9 const mochitestTestConfig = require("eslint-plugin-mozilla/lib/configs/mochitest-test.js");
10 const chromeTestConfig = require("eslint-plugin-mozilla/lib/configs/chrome-test.js");
11 const fs = require("fs");
12 const path = require("path");
15 * Some configurations have overrides, which can't be specified within overrides,
16 * so we need to remove them.
18 function removeOverrides(config) {
19 config = { ...config };
20 delete config.overrides;
24 const xpcshellTestPaths = [
27 "**/test*/xpcshell/**/",
30 const browserTestPaths = ["**/test*/**/browser*/"];
32 const mochitestTestPaths = [
33 // Note: we do not want to match testing/mochitest as that would apply
34 // too many globals for that directory.
36 "**/tests/mochitest/",
37 "**/test/mochitests/",
38 "testing/mochitest/tests/SimpleTest/",
39 "testing/mochitest/tests/Harness_sanity/",
42 const chromeTestPaths = ["**/test*/chrome/"];
44 const ignorePatterns = [
47 path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
64 .filter(p => p && !p.startsWith("#"))
65 .map(p => `devtools/client/debugger/src/${p}`),
69 parser: "@babel/eslint-parser",
73 configFile: path.join(__dirname, ".babel-eslint.rc.js"),
77 // Ignore eslint configurations in parent directories.
79 // New rules and configurations should generally be added in
80 // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
81 // allow external repositories that use the plugin to pick them up as well.
82 extends: ["plugin:mozilla/recommended"],
86 // All .eslintrc.js files are in the node environment, so turn that
88 // https://github.com/eslint/eslint/issues/13008
89 files: [".eslintrc.js"],
101 "no-redeclare": "warn",
102 "no-fallthrough": "warn",
103 "no-control-regex": "warn",
104 "no-throw-literal": "warn",
105 "no-useless-concat": "warn",
106 "consistent-return": "warn",
107 "mozilla/use-services": "warn",
108 "mozilla/use-includes-instead-of-indexOf": "warn",
109 "mozilla/no-compare-against-boolean-literals": "warn",
118 "js/src/builtin/**/*.js",
119 "js/src/shell/**/*.js",
122 // Curly brackets are required for all the tree via recommended.js,
123 // however these files aren't auto-fixable at the moment.
128 // TODO: Bug 1515949. Enable no-undef for gfx/
129 files: "gfx/layers/apz/test/mochitest/**",
135 ...removeOverrides(xpcshellTestConfig),
136 files: xpcshellTestPaths.map(path => `${path}**`),
137 excludedFiles: "devtools/**",
140 // If it is an xpcshell head file, we turn off global unused variable checks, as it
141 // would require searching the other test files to know if they are used or not.
142 // This would be expensive and slow, and it isn't worth it for head files.
143 // We could get developers to declare as exported, but that doesn't seem worth it.
144 files: xpcshellTestPaths.map(path => `${path}head*.js`),
156 // This section enables warning of no-unused-vars globally for all test*.js
157 // files in xpcshell test paths.
158 // These are turned into errors with selected exclusions in the next
160 // Bug 1612907: This section should go away once the exclusions are removed
161 // from the following section.
162 files: xpcshellTestPaths.map(path => `${path}test*.js`),
164 // No declaring variables that are never used
175 // This section makes global issues with no-unused-vars be reported as
176 // errors - except for the excluded lists which are being fixed in the
177 // dependencies of bug 1612907.
178 files: xpcshellTestPaths.map(path => `${path}test*.js`),
180 // These are suitable as good first bugs, take one or two related lines
182 "caps/tests/unit/test_origin.js",
183 "extensions/permissions/**",
184 "image/test/unit/**",
185 "intl/uconv/tests/unit/test_bug340714.js",
186 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
187 "modules/libjar/zipwriter/test/unit/test_alignment.js",
188 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
189 "modules/libjar/zipwriter/test/unit/test_storedata.js",
190 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
191 "modules/libpref/test/unit/test_dirtyPrefs.js",
192 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
193 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
195 // These are more complicated bugs which may require some in-depth
196 // investigation or different solutions. They are also likely to be
197 // a reasonable size.
198 "browser/components/**",
199 "browser/modules/**",
202 "security/manager/ssl/tests/unit/**",
204 "testing/xpcshell/**",
205 "toolkit/components/**",
206 "toolkit/modules/**",
209 // No declaring variables that are never used
220 ...browserTestConfig,
221 files: browserTestPaths.map(path => `${path}**`),
224 ...removeOverrides(mochitestTestConfig),
225 files: mochitestTestPaths.map(path => `${path}**`),
226 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
229 ...removeOverrides(chromeTestConfig),
230 files: chromeTestPaths.map(path => `${path}**`),
234 // Ideally we wouldn't be using the simpletest env here, but our uses of
235 // js files mean we pick up everything from the global scope, which could
236 // be any one of a number of html files. So we just allow the basics...
237 "mozilla/simpletest": true,
240 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
241 ...chromeTestPaths.map(path => `${path}/**/*.js`),
246 "netwerk/cookie/test/browser/**",
247 "netwerk/test/browser/**",
248 "netwerk/test/mochitests/**",
249 "netwerk/test/unit*/**",
252 "mozilla/no-arbitrary-setTimeout": "off",
253 "mozilla/no-define-cc-etc": "off",
254 "consistent-return": "off",
256 "no-global-assign": "off",
257 "no-nested-ternary": "off",
258 "no-redeclare": "off",
260 "no-throw-literal": "off",
264 files: ["layout/**"],
266 "object-shorthand": "off",
267 "mozilla/avoid-removeChild": "off",
268 "mozilla/consistent-if-bracing": "off",
269 "mozilla/reject-importGlobalProperties": "off",
270 "mozilla/no-arbitrary-setTimeout": "off",
271 "mozilla/no-define-cc-etc": "off",
272 "mozilla/use-chromeutils-generateqi": "off",
273 "mozilla/use-default-preference-values": "off",
274 "mozilla/use-includes-instead-of-indexOf": "off",
275 "mozilla/use-services": "off",
276 "mozilla/use-ownerGlobal": "off",
278 "consistent-return": "off",
279 "no-array-constructor": "off",
281 "no-cond-assign": "off",
282 "no-extra-boolean-cast": "off",
284 "no-func-assign": "off",
285 "no-global-assign": "off",
286 "no-implied-eval": "off",
287 "no-lonely-if": "off",
288 "no-nested-ternary": "off",
289 "no-new-wrappers": "off",
290 "no-redeclare": "off",
291 "no-restricted-globals": "off",
292 "no-return-await": "off",
293 "no-sequences": "off",
294 "no-throw-literal": "off",
295 "no-useless-concat": "off",
297 "no-unreachable": "off",
298 "no-unsanitized/method": "off",
299 "no-unsanitized/property": "off",
300 "no-unsafe-negation": "off",
301 "no-unused-vars": "off",
302 "no-useless-return": "off",
309 "dom/base/test/unit/test_serializers_entities*.js",
310 "dom/base/test/unit_ipc/**",
311 "dom/base/test/jsmodules/**",
320 "dom/media/tests/**",
321 "dom/media/webaudio/**",
322 "dom/media/webrtc/tests/**",
323 "dom/media/webspeech/**",
324 "dom/messagechannel/**",
328 "dom/performance/**",
330 "dom/quota/test/browser/**",
331 "dom/quota/test/common/**",
332 "dom/quota/test/mochitest/**",
333 "dom/quota/test/xpcshell/**",
334 "dom/security/test/cors/**",
335 "dom/security/test/csp/**",
336 "dom/security/test/mixedcontentblocker/**",
337 "dom/serviceworkers/**",
339 "dom/tests/mochitest/**",
350 "dom/ipc/test.xhtml",
353 "consistent-return": "off",
354 "mozilla/avoid-removeChild": "off",
355 "mozilla/consistent-if-bracing": "off",
356 "mozilla/no-arbitrary-setTimeout": "off",
357 "mozilla/no-compare-against-boolean-literals": "off",
358 "mozilla/no-define-cc-etc": "off",
359 "mozilla/reject-importGlobalProperties": "off",
360 "mozilla/use-cc-etc": "off",
361 "mozilla/use-chromeutils-generateqi": "off",
362 "mozilla/use-includes-instead-of-indexOf": "off",
363 "mozilla/use-ownerGlobal": "off",
364 "mozilla/use-services": "off",
365 "no-array-constructor": "off",
367 "no-cond-assign": "off",
368 "no-control-regex": "off",
369 "no-debugger": "off",
370 "no-else-return": "off",
373 "no-func-assign": "off",
374 "no-global-assign": "off",
375 "no-implied-eval": "off",
376 "no-lone-blocks": "off",
377 "no-lonely-if": "off",
378 "no-nested-ternary": "off",
379 "no-new-object": "off",
380 "no-new-wrappers": "off",
381 "no-redeclare": "off",
382 "no-return-await": "off",
383 "no-restricted-globals": "off",
384 "no-self-assign": "off",
385 "no-self-compare": "off",
386 "no-sequences": "off",
388 "no-shadow-restricted-names": "off",
389 "no-sparse-arrays": "off",
390 "no-throw-literal": "off",
391 "no-unreachable": "off",
392 "no-unsanitized/method": "off",
393 "no-unsanitized/property": "off",
395 "no-unused-vars": "off",
396 "no-useless-call": "off",
397 "no-useless-concat": "off",
398 "no-useless-return": "off",
404 "testing/mochitest/browser-harness.xhtml",
405 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
406 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
407 "testing/mochitest/chrome/test_sanityException.xhtml",
408 "testing/mochitest/chrome/test_sanityException2.xhtml",
409 "testing/mochitest/harness.xhtml",
412 "dot-notation": "off",
413 "object-shorthand": "off",
414 "mozilla/use-services": "off",
415 "mozilla/no-compare-against-boolean-literals": "off",
416 "mozilla/no-useless-parameters": "off",
417 "mozilla/no-useless-removeEventListener": "off",
418 "mozilla/use-cc-etc": "off",
419 "consistent-return": "off",
420 "no-fallthrough": "off",
421 "no-nested-ternary": "off",
422 "no-redeclare": "off",
423 "no-sequences": "off",
425 "no-throw-literal": "off",
427 "no-unsanitized/property": "off",
428 "no-unused-vars": "off",
429 "no-useless-call": "off",
434 "dom/base/test/chrome/file_bug1139964.xhtml",
435 "dom/base/test/chrome/file_bug549682.xhtml",
436 "dom/base/test/chrome/file_bug616841.xhtml",
437 "dom/base/test/chrome/file_bug990812-1.xhtml",
438 "dom/base/test/chrome/file_bug990812-2.xhtml",
439 "dom/base/test/chrome/file_bug990812-3.xhtml",
440 "dom/base/test/chrome/file_bug990812-4.xhtml",
441 "dom/base/test/chrome/file_bug990812-5.xhtml",
442 "dom/base/test/chrome/file_bug990812.xhtml",
443 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
444 "dom/base/test/chrome/test_bug339494.xhtml",
445 "dom/base/test/chrome/test_bug429785.xhtml",
446 "dom/base/test/chrome/test_bug467123.xhtml",
447 "dom/base/test/chrome/test_bug683852.xhtml",
448 "dom/base/test/chrome/test_bug780529.xhtml",
449 "dom/base/test/chrome/test_bug800386.xhtml",
450 "dom/base/test/chrome/test_bug884693.xhtml",
451 "dom/base/test/chrome/test_document-element-inserted.xhtml",
452 "dom/base/test/chrome/test_domparsing.xhtml",
453 "dom/base/test/chrome/title_window.xhtml",
454 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
455 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
456 "dom/base/test/test_domrequesthelper.xhtml",
457 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
458 "dom/console/tests/test_jsm.xhtml",
459 "dom/events/test/test_bug1412775.xhtml",
460 "dom/events/test/test_bug336682_2.xhtml",
461 "dom/events/test/test_bug415498.xhtml",
462 "dom/events/test/test_bug602962.xhtml",
463 "dom/events/test/test_bug617528.xhtml",
464 "dom/events/test/test_bug679494.xhtml",
465 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
466 "dom/indexedDB/test/test_wrappedArray.xhtml",
467 "dom/ipc/test.xhtml",
468 "dom/ipc/tests/test_process_error.xhtml",
469 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
470 "dom/security/test/general/test_bug1277803.xhtml",
471 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
472 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
473 "dom/system/tests/test_constants.xhtml",
474 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
475 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
476 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
477 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
478 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
479 "dom/tests/mochitest/chrome/window_focus.xhtml",
480 "dom/url/tests/test_bug883784.xhtml",
481 "dom/workers/test/test_WorkerDebugger.xhtml",
482 "dom/workers/test/test_WorkerDebugger_console.xhtml",
483 "dom/workers/test/test_fileReadSlice.xhtml",
484 "dom/workers/test/test_fileReaderSync.xhtml",
485 "dom/workers/test/test_fileSlice.xhtml",
488 "mozilla/no-useless-parameters": "off",
489 "mozilla/no-useless-removeEventListener": "off",
490 "mozilla/use-chromeutils-generateqi": "off",
491 "mozilla/use-services": "off",
493 "no-array-constructor": "off",
497 "no-lone-blocks": "off",
498 "no-redeclare": "off",
500 "no-throw-literal": "off",
501 "no-unsanitized/method": "off",
502 "no-useless-return": "off",
503 "object-shorthand": "off",
512 "editor/libeditor/tests/**",
513 "editor/spellchecker/tests/test_bug338427.html",
515 "image/test/browser/browser_image.js",
522 "security/manager/**",
524 "storage/test/unit/test_vacuum.js",
525 "taskcluster/docker/periodic-updates/scripts/**",
528 "widget/tests/test_assign_event_data.html",
531 "mozilla/prefer-boolean-length-check": "off",
535 // Rules of Hooks broadly checks for camelCase "use" identifiers, so
536 // enable only for paths actually using React to avoid false positives.
537 extends: ["plugin:react-hooks/recommended"],
539 "browser/components/newtab/**",
540 "browser/components/pocket/**",