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 // The expressions defined below for test paths are the main path formats we
25 // prefer to support for tests as they are commonly used across the tree.
26 // See https://firefox-source-docs.mozilla.org/code-quality/lint/linters/eslint.html#i-m-adding-tests-how-do-i-set-up-the-right-configuration
27 // for more information.
29 const xpcshellTestPaths = [
32 "**/test*/xpcshell/**/",
33 // Special case for xpcshell harness.
34 "testing/xpcshell/example/unit/",
37 const browserTestPaths = ["**/test*/**/browser*/"];
39 const mochitestTestPaths = [
40 // Note: we do not want to match testing/mochitest as that would apply
41 // too many globals for that directory.
43 "**/tests/mochitest/",
44 "**/test/mochitests/",
45 "testing/mochitest/tests/SimpleTest/",
46 "testing/mochitest/tests/Harness_sanity/",
49 const chromeTestPaths = ["**/test*/chrome/"];
51 const ignorePatterns = [
54 path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
71 .filter(p => p && !p.startsWith("#"))
72 .map(p => `devtools/client/debugger/src/${p}`),
76 parser: "@babel/eslint-parser",
80 configFile: path.join(__dirname, ".babel-eslint.rc.js"),
84 "import/extensions": [".mjs"],
87 // Ignore eslint configurations in parent directories.
89 // New rules and configurations should generally be added in
90 // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
91 // allow external repositories that use the plugin to pick them up as well.
92 extends: ["plugin:mozilla/recommended"],
93 plugins: ["mozilla", "import"],
96 // All .eslintrc.js files are in the node environment, so turn that
98 // https://github.com/eslint/eslint/issues/13008
99 files: [".eslintrc.js"],
108 "import/default": "error",
109 "import/export": "error",
110 "import/named": "error",
111 "import/namespace": "error",
112 "import/newline-after-import": "error",
113 "import/no-anonymous-default-export": "error",
114 "import/no-duplicates": "error",
115 "import/no-absolute-path": "error",
116 "import/no-named-default": "error",
117 "import/no-named-as-default": "error",
118 "import/no-named-as-default-member": "error",
119 "import/no-self-import": "error",
120 "import/no-unassigned-import": "error",
121 "import/no-unresolved": "error",
122 "import/no-useless-path-segments": "error",
127 // Bug 1773473 - Turn off no-unresolved for system mjs modules, as we
128 // do not yet have a resolver for resource:// uris.
130 // Bug 1773475 - For now, turn off no-unresolved on some paths where we import
131 // from node_modules, as the ESLint setup only installs modules at the
133 "devtools/shared/compatibility/**",
136 "import/no-unresolved": "off",
144 "js/src/builtin/**/*.js",
145 "js/src/shell/**/*.js",
148 // Curly brackets are required for all the tree via recommended.js,
149 // however these files aren't auto-fixable at the moment.
154 // TODO: Bug 1515949. Enable no-undef for gfx/
155 files: "gfx/layers/apz/test/mochitest/**",
161 ...removeOverrides(xpcshellTestConfig),
162 files: xpcshellTestPaths.map(path => `${path}**`),
163 excludedFiles: "devtools/**",
166 // If it is an xpcshell head file, we turn off global unused variable checks, as it
167 // would require searching the other test files to know if they are used or not.
168 // This would be expensive and slow, and it isn't worth it for head files.
169 // We could get developers to declare as exported, but that doesn't seem worth it.
170 files: xpcshellTestPaths.map(path => `${path}head*.js`),
182 // This section enables warning of no-unused-vars globally for all test*.js
183 // files in xpcshell test paths.
184 // These are turned into errors with selected exclusions in the next
186 // Bug 1612907: This section should go away once the exclusions are removed
187 // from the following section.
188 files: xpcshellTestPaths.map(path => `${path}test*.js`),
190 // No declaring variables that are never used
201 // This section makes global issues with no-unused-vars be reported as
202 // errors - except for the excluded lists which are being fixed in the
203 // dependencies of bug 1612907.
204 files: xpcshellTestPaths.map(path => `${path}test*.js`),
206 // These are suitable as good first bugs, take one or two related lines
208 "extensions/permissions/**",
209 "image/test/unit/**",
210 "intl/uconv/tests/unit/test_bug340714.js",
211 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
212 "modules/libjar/zipwriter/test/unit/test_alignment.js",
213 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
214 "modules/libjar/zipwriter/test/unit/test_storedata.js",
215 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
216 "modules/libpref/test/unit/test_dirtyPrefs.js",
217 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
218 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
220 // These are more complicated bugs which may require some in-depth
221 // investigation or different solutions. They are also likely to be
222 // a reasonable size.
223 "browser/components/**",
224 "browser/modules/**",
227 "security/manager/ssl/tests/unit/**",
228 "toolkit/components/**",
229 "toolkit/modules/**",
232 // No declaring variables that are never used
243 ...browserTestConfig,
244 files: browserTestPaths.map(path => `${path}**`),
247 ...removeOverrides(mochitestTestConfig),
248 files: mochitestTestPaths.map(path => `${path}**`),
249 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
252 ...removeOverrides(chromeTestConfig),
253 files: chromeTestPaths.map(path => `${path}**`),
257 // Ideally we wouldn't be using the simpletest env here, but our uses of
258 // js files mean we pick up everything from the global scope, which could
259 // be any one of a number of html files. So we just allow the basics...
260 "mozilla/simpletest": true,
263 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
264 ...chromeTestPaths.map(path => `${path}/**/*.js`),
269 "netwerk/cookie/test/browser/**",
270 "netwerk/test/browser/**",
271 "netwerk/test/mochitests/**",
272 "netwerk/test/unit*/**",
275 "mozilla/no-arbitrary-setTimeout": "off",
276 "mozilla/no-define-cc-etc": "off",
277 "consistent-return": "off",
279 "no-global-assign": "off",
280 "no-nested-ternary": "off",
281 "no-redeclare": "off",
283 "no-throw-literal": "off",
287 files: ["layout/**"],
289 "object-shorthand": "off",
290 "mozilla/avoid-removeChild": "off",
291 "mozilla/consistent-if-bracing": "off",
292 "mozilla/reject-importGlobalProperties": "off",
293 "mozilla/no-arbitrary-setTimeout": "off",
294 "mozilla/no-define-cc-etc": "off",
295 "mozilla/use-chromeutils-generateqi": "off",
296 "mozilla/use-default-preference-values": "off",
297 "mozilla/use-includes-instead-of-indexOf": "off",
298 "mozilla/use-services": "off",
299 "mozilla/use-ownerGlobal": "off",
301 "consistent-return": "off",
302 "no-array-constructor": "off",
304 "no-cond-assign": "off",
305 "no-extra-boolean-cast": "off",
307 "no-func-assign": "off",
308 "no-global-assign": "off",
309 "no-implied-eval": "off",
310 "no-lonely-if": "off",
311 "no-nested-ternary": "off",
312 "no-new-wrappers": "off",
313 "no-redeclare": "off",
314 "no-restricted-globals": "off",
315 "no-return-await": "off",
316 "no-sequences": "off",
317 "no-throw-literal": "off",
318 "no-useless-concat": "off",
320 "no-unreachable": "off",
321 "no-unsanitized/method": "off",
322 "no-unsanitized/property": "off",
323 "no-unsafe-negation": "off",
324 "no-unused-vars": "off",
325 "no-useless-return": "off",
332 "dom/base/test/unit/test_serializers_entities*.js",
333 "dom/base/test/unit_ipc/**",
334 "dom/base/test/jsmodules/**",
343 "dom/media/tests/**",
344 "dom/media/webaudio/**",
345 "dom/media/webrtc/tests/**",
346 "dom/media/webspeech/**",
347 "dom/messagechannel/**",
351 "dom/performance/**",
353 "dom/quota/test/browser/**",
354 "dom/quota/test/common/**",
355 "dom/quota/test/mochitest/**",
356 "dom/quota/test/xpcshell/**",
357 "dom/security/test/cors/**",
358 "dom/security/test/csp/**",
359 "dom/security/test/mixedcontentblocker/**",
360 "dom/serviceworkers/**",
362 "dom/tests/mochitest/**",
373 "dom/ipc/test.xhtml",
376 "consistent-return": "off",
377 "mozilla/avoid-removeChild": "off",
378 "mozilla/consistent-if-bracing": "off",
379 "mozilla/no-arbitrary-setTimeout": "off",
380 "mozilla/no-compare-against-boolean-literals": "off",
381 "mozilla/no-define-cc-etc": "off",
382 "mozilla/reject-importGlobalProperties": "off",
383 "mozilla/use-cc-etc": "off",
384 "mozilla/use-chromeutils-generateqi": "off",
385 "mozilla/use-includes-instead-of-indexOf": "off",
386 "mozilla/use-ownerGlobal": "off",
387 "mozilla/use-services": "off",
388 "no-array-constructor": "off",
390 "no-cond-assign": "off",
391 "no-control-regex": "off",
392 "no-debugger": "off",
393 "no-else-return": "off",
396 "no-func-assign": "off",
397 "no-global-assign": "off",
398 "no-implied-eval": "off",
399 "no-lone-blocks": "off",
400 "no-lonely-if": "off",
401 "no-nested-ternary": "off",
402 "no-new-object": "off",
403 "no-new-wrappers": "off",
404 "no-redeclare": "off",
405 "no-return-await": "off",
406 "no-restricted-globals": "off",
407 "no-self-assign": "off",
408 "no-self-compare": "off",
409 "no-sequences": "off",
411 "no-shadow-restricted-names": "off",
412 "no-sparse-arrays": "off",
413 "no-throw-literal": "off",
414 "no-unreachable": "off",
415 "no-unsanitized/method": "off",
416 "no-unsanitized/property": "off",
418 "no-unused-vars": "off",
419 "no-useless-call": "off",
420 "no-useless-concat": "off",
421 "no-useless-return": "off",
427 "testing/mochitest/browser-harness.xhtml",
428 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
429 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
430 "testing/mochitest/chrome/test_sanityException.xhtml",
431 "testing/mochitest/chrome/test_sanityException2.xhtml",
432 "testing/mochitest/harness.xhtml",
435 "dot-notation": "off",
436 "object-shorthand": "off",
437 "mozilla/use-services": "off",
438 "mozilla/no-compare-against-boolean-literals": "off",
439 "mozilla/no-useless-parameters": "off",
440 "mozilla/no-useless-removeEventListener": "off",
441 "mozilla/use-cc-etc": "off",
442 "consistent-return": "off",
443 "no-fallthrough": "off",
444 "no-nested-ternary": "off",
445 "no-redeclare": "off",
446 "no-sequences": "off",
448 "no-throw-literal": "off",
450 "no-unsanitized/property": "off",
451 "no-unused-vars": "off",
452 "no-useless-call": "off",
457 "dom/base/test/chrome/file_bug1139964.xhtml",
458 "dom/base/test/chrome/file_bug549682.xhtml",
459 "dom/base/test/chrome/file_bug616841.xhtml",
460 "dom/base/test/chrome/file_bug990812-1.xhtml",
461 "dom/base/test/chrome/file_bug990812-2.xhtml",
462 "dom/base/test/chrome/file_bug990812-3.xhtml",
463 "dom/base/test/chrome/file_bug990812-4.xhtml",
464 "dom/base/test/chrome/file_bug990812-5.xhtml",
465 "dom/base/test/chrome/file_bug990812.xhtml",
466 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
467 "dom/base/test/chrome/test_bug339494.xhtml",
468 "dom/base/test/chrome/test_bug429785.xhtml",
469 "dom/base/test/chrome/test_bug467123.xhtml",
470 "dom/base/test/chrome/test_bug683852.xhtml",
471 "dom/base/test/chrome/test_bug780529.xhtml",
472 "dom/base/test/chrome/test_bug800386.xhtml",
473 "dom/base/test/chrome/test_bug884693.xhtml",
474 "dom/base/test/chrome/test_document-element-inserted.xhtml",
475 "dom/base/test/chrome/test_domparsing.xhtml",
476 "dom/base/test/chrome/title_window.xhtml",
477 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
478 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
479 "dom/base/test/test_domrequesthelper.xhtml",
480 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
481 "dom/console/tests/test_jsm.xhtml",
482 "dom/events/test/test_bug1412775.xhtml",
483 "dom/events/test/test_bug336682_2.xhtml",
484 "dom/events/test/test_bug415498.xhtml",
485 "dom/events/test/test_bug602962.xhtml",
486 "dom/events/test/test_bug617528.xhtml",
487 "dom/events/test/test_bug679494.xhtml",
488 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
489 "dom/indexedDB/test/test_wrappedArray.xhtml",
490 "dom/ipc/test.xhtml",
491 "dom/ipc/tests/test_process_error.xhtml",
492 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
493 "dom/security/test/general/test_bug1277803.xhtml",
494 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
495 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
496 "dom/system/tests/test_constants.xhtml",
497 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
498 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
499 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
500 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
501 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
502 "dom/tests/mochitest/chrome/window_focus.xhtml",
503 "dom/url/tests/test_bug883784.xhtml",
504 "dom/workers/test/test_WorkerDebugger.xhtml",
505 "dom/workers/test/test_WorkerDebugger_console.xhtml",
506 "dom/workers/test/test_fileReadSlice.xhtml",
507 "dom/workers/test/test_fileReaderSync.xhtml",
508 "dom/workers/test/test_fileSlice.xhtml",
511 "mozilla/no-useless-parameters": "off",
512 "mozilla/no-useless-removeEventListener": "off",
513 "mozilla/use-chromeutils-generateqi": "off",
514 "mozilla/use-services": "off",
516 "no-array-constructor": "off",
520 "no-lone-blocks": "off",
521 "no-redeclare": "off",
523 "no-throw-literal": "off",
524 "no-unsanitized/method": "off",
525 "no-useless-return": "off",
526 "object-shorthand": "off",
535 "editor/libeditor/tests/**",
536 "editor/spellchecker/tests/test_bug338427.html",
538 "image/test/browser/browser_image.js",
545 "security/manager/**",
547 "storage/test/unit/test_vacuum.js",
548 "taskcluster/docker/periodic-updates/scripts/**",
551 "widget/tests/test_assign_event_data.html",
554 "mozilla/prefer-boolean-length-check": "off",
558 // Rules of Hooks broadly checks for camelCase "use" identifiers, so
559 // enable only for paths actually using React to avoid false positives.
560 extends: ["plugin:react-hooks/recommended"],
562 "browser/components/newtab/**",
563 "browser/components/pocket/**",
568 // Turn off the osfile rule for osfile.
569 files: ["toolkit/components/osfile/**"],
571 "mozilla/reject-osfile": "off",