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 "import/extensions": [".mjs"],
80 // Ignore eslint configurations in parent directories.
82 // New rules and configurations should generally be added in
83 // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
84 // allow external repositories that use the plugin to pick them up as well.
85 extends: ["plugin:mozilla/recommended"],
86 plugins: ["mozilla", "import"],
89 // All .eslintrc.js files are in the node environment, so turn that
91 // https://github.com/eslint/eslint/issues/13008
92 files: [".eslintrc.js"],
101 "import/default": "error",
102 "import/export": "error",
103 "import/named": "error",
104 "import/namespace": "error",
105 "import/newline-after-import": "error",
106 "import/no-anonymous-default-export": "error",
107 "import/no-duplicates": "error",
108 "import/no-absolute-path": "error",
109 "import/no-named-default": "error",
110 "import/no-named-as-default": "error",
111 "import/no-named-as-default-member": "error",
112 "import/no-self-import": "error",
113 "import/no-unassigned-import": "error",
114 "import/no-unresolved": "error",
115 "import/no-useless-path-segments": "error",
120 // Bug 1773473 - Turn off no-unresolved for system mjs modules, as we
121 // do not yet have a resolver for resource:// uris.
123 // Bug 1773475 - For now, turn off no-unresolved on some paths where we import
124 // from node_modules, as the ESLint setup only installs modules at the
126 "devtools/shared/compatibility/**",
129 "import/no-unresolved": "off",
137 "js/src/builtin/**/*.js",
138 "js/src/shell/**/*.js",
141 // Curly brackets are required for all the tree via recommended.js,
142 // however these files aren't auto-fixable at the moment.
147 // TODO: Bug 1515949. Enable no-undef for gfx/
148 files: "gfx/layers/apz/test/mochitest/**",
154 ...removeOverrides(xpcshellTestConfig),
155 files: xpcshellTestPaths.map(path => `${path}**`),
156 excludedFiles: "devtools/**",
159 // If it is an xpcshell head file, we turn off global unused variable checks, as it
160 // would require searching the other test files to know if they are used or not.
161 // This would be expensive and slow, and it isn't worth it for head files.
162 // We could get developers to declare as exported, but that doesn't seem worth it.
163 files: xpcshellTestPaths.map(path => `${path}head*.js`),
175 // This section enables warning of no-unused-vars globally for all test*.js
176 // files in xpcshell test paths.
177 // These are turned into errors with selected exclusions in the next
179 // Bug 1612907: This section should go away once the exclusions are removed
180 // from the following section.
181 files: xpcshellTestPaths.map(path => `${path}test*.js`),
183 // No declaring variables that are never used
194 // This section makes global issues with no-unused-vars be reported as
195 // errors - except for the excluded lists which are being fixed in the
196 // dependencies of bug 1612907.
197 files: xpcshellTestPaths.map(path => `${path}test*.js`),
199 // These are suitable as good first bugs, take one or two related lines
201 "caps/tests/unit/test_origin.js",
202 "extensions/permissions/**",
203 "image/test/unit/**",
204 "intl/uconv/tests/unit/test_bug340714.js",
205 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
206 "modules/libjar/zipwriter/test/unit/test_alignment.js",
207 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
208 "modules/libjar/zipwriter/test/unit/test_storedata.js",
209 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
210 "modules/libpref/test/unit/test_dirtyPrefs.js",
211 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
212 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
214 // These are more complicated bugs which may require some in-depth
215 // investigation or different solutions. They are also likely to be
216 // a reasonable size.
217 "browser/components/**",
218 "browser/modules/**",
221 "security/manager/ssl/tests/unit/**",
223 "testing/xpcshell/**",
224 "toolkit/components/**",
225 "toolkit/modules/**",
228 // No declaring variables that are never used
239 ...browserTestConfig,
240 files: browserTestPaths.map(path => `${path}**`),
243 ...removeOverrides(mochitestTestConfig),
244 files: mochitestTestPaths.map(path => `${path}**`),
245 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
248 ...removeOverrides(chromeTestConfig),
249 files: chromeTestPaths.map(path => `${path}**`),
253 // Ideally we wouldn't be using the simpletest env here, but our uses of
254 // js files mean we pick up everything from the global scope, which could
255 // be any one of a number of html files. So we just allow the basics...
256 "mozilla/simpletest": true,
259 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
260 ...chromeTestPaths.map(path => `${path}/**/*.js`),
265 "netwerk/cookie/test/browser/**",
266 "netwerk/test/browser/**",
267 "netwerk/test/mochitests/**",
268 "netwerk/test/unit*/**",
271 "mozilla/no-arbitrary-setTimeout": "off",
272 "mozilla/no-define-cc-etc": "off",
273 "consistent-return": "off",
275 "no-global-assign": "off",
276 "no-nested-ternary": "off",
277 "no-redeclare": "off",
279 "no-throw-literal": "off",
283 files: ["layout/**"],
285 "object-shorthand": "off",
286 "mozilla/avoid-removeChild": "off",
287 "mozilla/consistent-if-bracing": "off",
288 "mozilla/reject-importGlobalProperties": "off",
289 "mozilla/no-arbitrary-setTimeout": "off",
290 "mozilla/no-define-cc-etc": "off",
291 "mozilla/use-chromeutils-generateqi": "off",
292 "mozilla/use-default-preference-values": "off",
293 "mozilla/use-includes-instead-of-indexOf": "off",
294 "mozilla/use-services": "off",
295 "mozilla/use-ownerGlobal": "off",
297 "consistent-return": "off",
298 "no-array-constructor": "off",
300 "no-cond-assign": "off",
301 "no-extra-boolean-cast": "off",
303 "no-func-assign": "off",
304 "no-global-assign": "off",
305 "no-implied-eval": "off",
306 "no-lonely-if": "off",
307 "no-nested-ternary": "off",
308 "no-new-wrappers": "off",
309 "no-redeclare": "off",
310 "no-restricted-globals": "off",
311 "no-return-await": "off",
312 "no-sequences": "off",
313 "no-throw-literal": "off",
314 "no-useless-concat": "off",
316 "no-unreachable": "off",
317 "no-unsanitized/method": "off",
318 "no-unsanitized/property": "off",
319 "no-unsafe-negation": "off",
320 "no-unused-vars": "off",
321 "no-useless-return": "off",
328 "dom/base/test/unit/test_serializers_entities*.js",
329 "dom/base/test/unit_ipc/**",
330 "dom/base/test/jsmodules/**",
339 "dom/media/tests/**",
340 "dom/media/webaudio/**",
341 "dom/media/webrtc/tests/**",
342 "dom/media/webspeech/**",
343 "dom/messagechannel/**",
347 "dom/performance/**",
349 "dom/quota/test/browser/**",
350 "dom/quota/test/common/**",
351 "dom/quota/test/mochitest/**",
352 "dom/quota/test/xpcshell/**",
353 "dom/security/test/cors/**",
354 "dom/security/test/csp/**",
355 "dom/security/test/mixedcontentblocker/**",
356 "dom/serviceworkers/**",
358 "dom/tests/mochitest/**",
369 "dom/ipc/test.xhtml",
372 "consistent-return": "off",
373 "mozilla/avoid-removeChild": "off",
374 "mozilla/consistent-if-bracing": "off",
375 "mozilla/no-arbitrary-setTimeout": "off",
376 "mozilla/no-compare-against-boolean-literals": "off",
377 "mozilla/no-define-cc-etc": "off",
378 "mozilla/reject-importGlobalProperties": "off",
379 "mozilla/use-cc-etc": "off",
380 "mozilla/use-chromeutils-generateqi": "off",
381 "mozilla/use-includes-instead-of-indexOf": "off",
382 "mozilla/use-ownerGlobal": "off",
383 "mozilla/use-services": "off",
384 "no-array-constructor": "off",
386 "no-cond-assign": "off",
387 "no-control-regex": "off",
388 "no-debugger": "off",
389 "no-else-return": "off",
392 "no-func-assign": "off",
393 "no-global-assign": "off",
394 "no-implied-eval": "off",
395 "no-lone-blocks": "off",
396 "no-lonely-if": "off",
397 "no-nested-ternary": "off",
398 "no-new-object": "off",
399 "no-new-wrappers": "off",
400 "no-redeclare": "off",
401 "no-return-await": "off",
402 "no-restricted-globals": "off",
403 "no-self-assign": "off",
404 "no-self-compare": "off",
405 "no-sequences": "off",
407 "no-shadow-restricted-names": "off",
408 "no-sparse-arrays": "off",
409 "no-throw-literal": "off",
410 "no-unreachable": "off",
411 "no-unsanitized/method": "off",
412 "no-unsanitized/property": "off",
414 "no-unused-vars": "off",
415 "no-useless-call": "off",
416 "no-useless-concat": "off",
417 "no-useless-return": "off",
423 "testing/mochitest/browser-harness.xhtml",
424 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
425 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
426 "testing/mochitest/chrome/test_sanityException.xhtml",
427 "testing/mochitest/chrome/test_sanityException2.xhtml",
428 "testing/mochitest/harness.xhtml",
431 "dot-notation": "off",
432 "object-shorthand": "off",
433 "mozilla/use-services": "off",
434 "mozilla/no-compare-against-boolean-literals": "off",
435 "mozilla/no-useless-parameters": "off",
436 "mozilla/no-useless-removeEventListener": "off",
437 "mozilla/use-cc-etc": "off",
438 "consistent-return": "off",
439 "no-fallthrough": "off",
440 "no-nested-ternary": "off",
441 "no-redeclare": "off",
442 "no-sequences": "off",
444 "no-throw-literal": "off",
446 "no-unsanitized/property": "off",
447 "no-unused-vars": "off",
448 "no-useless-call": "off",
453 "dom/base/test/chrome/file_bug1139964.xhtml",
454 "dom/base/test/chrome/file_bug549682.xhtml",
455 "dom/base/test/chrome/file_bug616841.xhtml",
456 "dom/base/test/chrome/file_bug990812-1.xhtml",
457 "dom/base/test/chrome/file_bug990812-2.xhtml",
458 "dom/base/test/chrome/file_bug990812-3.xhtml",
459 "dom/base/test/chrome/file_bug990812-4.xhtml",
460 "dom/base/test/chrome/file_bug990812-5.xhtml",
461 "dom/base/test/chrome/file_bug990812.xhtml",
462 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
463 "dom/base/test/chrome/test_bug339494.xhtml",
464 "dom/base/test/chrome/test_bug429785.xhtml",
465 "dom/base/test/chrome/test_bug467123.xhtml",
466 "dom/base/test/chrome/test_bug683852.xhtml",
467 "dom/base/test/chrome/test_bug780529.xhtml",
468 "dom/base/test/chrome/test_bug800386.xhtml",
469 "dom/base/test/chrome/test_bug884693.xhtml",
470 "dom/base/test/chrome/test_document-element-inserted.xhtml",
471 "dom/base/test/chrome/test_domparsing.xhtml",
472 "dom/base/test/chrome/title_window.xhtml",
473 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
474 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
475 "dom/base/test/test_domrequesthelper.xhtml",
476 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
477 "dom/console/tests/test_jsm.xhtml",
478 "dom/events/test/test_bug1412775.xhtml",
479 "dom/events/test/test_bug336682_2.xhtml",
480 "dom/events/test/test_bug415498.xhtml",
481 "dom/events/test/test_bug602962.xhtml",
482 "dom/events/test/test_bug617528.xhtml",
483 "dom/events/test/test_bug679494.xhtml",
484 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
485 "dom/indexedDB/test/test_wrappedArray.xhtml",
486 "dom/ipc/test.xhtml",
487 "dom/ipc/tests/test_process_error.xhtml",
488 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
489 "dom/security/test/general/test_bug1277803.xhtml",
490 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
491 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
492 "dom/system/tests/test_constants.xhtml",
493 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
494 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
495 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
496 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
497 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
498 "dom/tests/mochitest/chrome/window_focus.xhtml",
499 "dom/url/tests/test_bug883784.xhtml",
500 "dom/workers/test/test_WorkerDebugger.xhtml",
501 "dom/workers/test/test_WorkerDebugger_console.xhtml",
502 "dom/workers/test/test_fileReadSlice.xhtml",
503 "dom/workers/test/test_fileReaderSync.xhtml",
504 "dom/workers/test/test_fileSlice.xhtml",
507 "mozilla/no-useless-parameters": "off",
508 "mozilla/no-useless-removeEventListener": "off",
509 "mozilla/use-chromeutils-generateqi": "off",
510 "mozilla/use-services": "off",
512 "no-array-constructor": "off",
516 "no-lone-blocks": "off",
517 "no-redeclare": "off",
519 "no-throw-literal": "off",
520 "no-unsanitized/method": "off",
521 "no-useless-return": "off",
522 "object-shorthand": "off",
531 "editor/libeditor/tests/**",
532 "editor/spellchecker/tests/test_bug338427.html",
534 "image/test/browser/browser_image.js",
541 "security/manager/**",
543 "storage/test/unit/test_vacuum.js",
544 "taskcluster/docker/periodic-updates/scripts/**",
547 "widget/tests/test_assign_event_data.html",
550 "mozilla/prefer-boolean-length-check": "off",
554 // Rules of Hooks broadly checks for camelCase "use" identifiers, so
555 // enable only for paths actually using React to avoid false positives.
556 extends: ["plugin:react-hooks/recommended"],
558 "browser/components/newtab/**",
559 "browser/components/pocket/**",
564 // Turn off the osfile rule for osfile.
565 files: ["toolkit/components/osfile/**"],
567 "mozilla/reject-osfile": "off",