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 { testPaths } = require("./.eslintrc-test-paths.js");
12 const fs = require("fs");
13 const path = require("path");
16 * Some configurations have overrides, which can't be specified within overrides,
17 * so we need to remove them.
19 function removeOverrides(config) {
20 config = { ...config };
21 delete config.overrides;
25 const ignorePatterns = [
28 path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
45 .filter(p => p && !p.startsWith("#"))
46 .map(p => `devtools/client/debugger/src/${p}`),
50 parser: "@babel/eslint-parser",
54 configFile: path.join(__dirname, ".babel-eslint.rc.js"),
58 "import/extensions": [".mjs"],
61 // Ignore eslint configurations in parent directories.
63 // New rules and configurations should generally be added in
64 // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
65 // allow external repositories that use the plugin to pick them up as well.
66 extends: ["plugin:mozilla/recommended"],
67 plugins: ["mozilla", "import"],
70 // All .eslintrc.js files are in the node environment, so turn that
72 // https://github.com/eslint/eslint/issues/13008
73 files: [".eslintrc.js"],
82 "import/default": "error",
83 "import/export": "error",
84 "import/named": "error",
85 "import/namespace": "error",
86 "import/newline-after-import": "error",
87 "import/no-anonymous-default-export": "error",
88 "import/no-duplicates": "error",
89 "import/no-absolute-path": "error",
90 "import/no-named-default": "error",
91 "import/no-named-as-default": "error",
92 "import/no-named-as-default-member": "error",
93 "import/no-self-import": "error",
94 "import/no-unassigned-import": "error",
95 "import/no-unresolved": [
97 // Bug 1773473 - Ignore resolver URLs for chrome and resource as we
98 // do not yet have a resolver for them.
99 { ignore: ["chrome://", "resource://"] },
101 "import/no-useless-path-segments": "error",
106 // Bug 1773475 - For now, turn off no-unresolved on some paths where we import
107 // from node_modules, as the ESLint setup only installs modules at the
109 "devtools/shared/compatibility/**",
112 "import/no-unresolved": "off",
116 files: ["*.html", "*.xhtml", "*.xml"],
118 // Curly brackets are required for all the tree via recommended.js,
119 // however these files aren't auto-fixable at the moment.
124 // TODO: Bug 1515949. Enable no-undef for gfx/
125 files: "gfx/layers/apz/test/mochitest/**",
131 ...removeOverrides(xpcshellTestConfig),
132 files: testPaths.xpcshell.map(path => `${path}**`),
135 // If it is an xpcshell head file, we turn off global unused variable checks, as it
136 // would require searching the other test files to know if they are used or not.
137 // This would be expensive and slow, and it isn't worth it for head files.
138 // We could get developers to declare as exported, but that doesn't seem worth it.
139 files: testPaths.xpcshell.map(path => `${path}head*.js`),
151 // This section enables warning of no-unused-vars globally for all test*.js
152 // files in xpcshell test paths.
153 // These are turned into errors with selected exclusions in the next
155 // Bug 1612907: This section should go away once the exclusions are removed
156 // from the following section.
157 files: testPaths.xpcshell.map(path => `${path}test*.js`),
159 // No declaring variables that are never used
170 // This section makes global issues with no-unused-vars be reported as
171 // errors - except for the excluded lists which are being fixed in the
172 // dependencies of bug 1612907.
173 files: testPaths.xpcshell.map(path => `${path}test*.js`),
175 // These are suitable as good first bugs, take one or two related lines
177 "extensions/permissions/**",
178 "image/test/unit/**",
179 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
180 "modules/libjar/zipwriter/test/unit/test_alignment.js",
181 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
182 "modules/libjar/zipwriter/test/unit/test_storedata.js",
183 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
184 "modules/libpref/test/unit/test_dirtyPrefs.js",
185 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
186 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
188 // These are more complicated bugs which may require some in-depth
189 // investigation or different solutions. They are also likely to be
190 // a reasonable size.
194 // No declaring variables that are never used
205 ...browserTestConfig,
206 files: testPaths.browser.map(path => `${path}**`),
209 ...removeOverrides(mochitestTestConfig),
210 files: testPaths.mochitest.map(path => `${path}**`),
211 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
214 ...removeOverrides(chromeTestConfig),
215 files: testPaths.chrome.map(path => `${path}**`),
219 // Ideally we wouldn't be using the simpletest env here, but our uses of
220 // js files mean we pick up everything from the global scope, which could
221 // be any one of a number of html files. So we just allow the basics...
222 "mozilla/simpletest": true,
225 ...testPaths.mochitest.map(path => `${path}/**/*.js`),
226 ...testPaths.chrome.map(path => `${path}/**/*.js`),
230 files: ["netwerk/test/mochitests/**", "netwerk/test/unit*/**"],
236 files: ["layout/**"],
238 "object-shorthand": "off",
239 "mozilla/avoid-removeChild": "off",
240 "mozilla/consistent-if-bracing": "off",
241 "mozilla/reject-importGlobalProperties": "off",
242 "mozilla/no-arbitrary-setTimeout": "off",
243 "mozilla/no-define-cc-etc": "off",
244 "mozilla/prefer-boolean-length-check": "off",
245 "mozilla/use-chromeutils-generateqi": "off",
246 "mozilla/use-default-preference-values": "off",
247 "mozilla/use-includes-instead-of-indexOf": "off",
248 "mozilla/use-services": "off",
249 "mozilla/use-ownerGlobal": "off",
251 "consistent-return": "off",
252 "no-array-constructor": "off",
254 "no-cond-assign": "off",
255 "no-extra-boolean-cast": "off",
257 "no-func-assign": "off",
258 "no-global-assign": "off",
259 "no-implied-eval": "off",
260 "no-lonely-if": "off",
261 "no-nested-ternary": "off",
262 "no-new-wrappers": "off",
263 "no-redeclare": "off",
264 "no-restricted-globals": "off",
265 "no-return-await": "off",
266 "no-sequences": "off",
267 "no-throw-literal": "off",
268 "no-useless-concat": "off",
270 "no-unreachable": "off",
271 "no-unsanitized/method": "off",
272 "no-unsanitized/property": "off",
273 "no-unsafe-negation": "off",
274 "no-unused-vars": "off",
275 "no-useless-return": "off",
280 "dom/animation/test/**",
282 "dom/base/test/unit/test_serializers_entities*.js",
283 "dom/base/test/unit_ipc/**",
284 "dom/base/test/jsmodules/**",
285 "dom/canvas/test/**",
286 "dom/encoding/test/**",
287 "dom/events/test/**",
288 "dom/fetch/tests/**",
289 "dom/file/ipc/tests/**",
293 "dom/media/tests/**",
294 "dom/media/webaudio/test/**",
295 "dom/media/webrtc/tests/**",
296 "dom/media/webspeech/recognition/test/**",
297 "dom/media/webspeech/synth/test/**",
298 "dom/messagechannel/tests/**",
300 "dom/network/tests/**",
301 "dom/payments/test/**",
302 "dom/performance/tests/**",
303 "dom/quota/test/browser/**",
304 "dom/quota/test/common/**",
305 "dom/quota/test/mochitest/**",
306 "dom/quota/test/xpcshell/**",
307 "dom/security/test/cors/**",
308 "dom/security/test/csp/**",
309 "dom/security/test/mixedcontentblocker/**",
310 "dom/serviceworkers/test/**",
312 "dom/tests/mochitest/**",
315 "dom/webauthn/tests/**",
316 "dom/webgpu/mochitest/**",
317 "dom/websocket/tests/**",
318 "dom/workers/test/**",
319 "dom/worklet/tests/**",
323 "dom/ipc/test.xhtml",
326 "consistent-return": "off",
327 "mozilla/avoid-removeChild": "off",
328 "mozilla/consistent-if-bracing": "off",
329 "mozilla/no-arbitrary-setTimeout": "off",
330 "mozilla/no-compare-against-boolean-literals": "off",
331 "mozilla/no-define-cc-etc": "off",
332 "mozilla/reject-importGlobalProperties": "off",
333 "mozilla/use-cc-etc": "off",
334 "mozilla/use-chromeutils-generateqi": "off",
335 "mozilla/use-includes-instead-of-indexOf": "off",
336 "mozilla/use-ownerGlobal": "off",
337 "mozilla/use-services": "off",
338 "no-array-constructor": "off",
340 "no-cond-assign": "off",
341 "no-control-regex": "off",
342 "no-debugger": "off",
343 "no-else-return": "off",
346 "no-func-assign": "off",
347 "no-global-assign": "off",
348 "no-implied-eval": "off",
349 "no-lone-blocks": "off",
350 "no-lonely-if": "off",
351 "no-nested-ternary": "off",
352 "no-new-object": "off",
353 "no-new-wrappers": "off",
354 "no-redeclare": "off",
355 "no-return-await": "off",
356 "no-restricted-globals": "off",
357 "no-self-assign": "off",
358 "no-self-compare": "off",
359 "no-sequences": "off",
361 "no-shadow-restricted-names": "off",
362 "no-sparse-arrays": "off",
363 "no-throw-literal": "off",
364 "no-unreachable": "off",
365 "no-unsanitized/method": "off",
366 "no-unsanitized/property": "off",
368 "no-unused-vars": "off",
369 "no-useless-call": "off",
370 "no-useless-concat": "off",
371 "no-useless-return": "off",
377 "testing/mochitest/browser-harness.xhtml",
378 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
379 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
380 "testing/mochitest/chrome/test_sanityException.xhtml",
381 "testing/mochitest/chrome/test_sanityException2.xhtml",
382 "testing/mochitest/harness.xhtml",
385 "dot-notation": "off",
386 "object-shorthand": "off",
387 "mozilla/use-services": "off",
388 "mozilla/no-compare-against-boolean-literals": "off",
389 "mozilla/no-useless-parameters": "off",
390 "mozilla/no-useless-removeEventListener": "off",
391 "mozilla/use-cc-etc": "off",
392 "consistent-return": "off",
393 "no-fallthrough": "off",
394 "no-nested-ternary": "off",
395 "no-redeclare": "off",
396 "no-sequences": "off",
398 "no-throw-literal": "off",
400 "no-unsanitized/property": "off",
401 "no-unused-vars": "off",
402 "no-useless-call": "off",
407 "dom/base/test/chrome/file_bug1139964.xhtml",
408 "dom/base/test/chrome/file_bug549682.xhtml",
409 "dom/base/test/chrome/file_bug616841.xhtml",
410 "dom/base/test/chrome/file_bug990812-1.xhtml",
411 "dom/base/test/chrome/file_bug990812-2.xhtml",
412 "dom/base/test/chrome/file_bug990812-3.xhtml",
413 "dom/base/test/chrome/file_bug990812-4.xhtml",
414 "dom/base/test/chrome/file_bug990812-5.xhtml",
415 "dom/base/test/chrome/file_bug990812.xhtml",
416 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
417 "dom/base/test/chrome/test_bug339494.xhtml",
418 "dom/base/test/chrome/test_bug429785.xhtml",
419 "dom/base/test/chrome/test_bug467123.xhtml",
420 "dom/base/test/chrome/test_bug683852.xhtml",
421 "dom/base/test/chrome/test_bug780529.xhtml",
422 "dom/base/test/chrome/test_bug800386.xhtml",
423 "dom/base/test/chrome/test_bug884693.xhtml",
424 "dom/base/test/chrome/test_document-element-inserted.xhtml",
425 "dom/base/test/chrome/test_domparsing.xhtml",
426 "dom/base/test/chrome/title_window.xhtml",
427 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
428 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
429 "dom/base/test/test_domrequesthelper.xhtml",
430 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
431 "dom/console/tests/test_jsm.xhtml",
432 "dom/events/test/test_bug1412775.xhtml",
433 "dom/events/test/test_bug336682_2.xhtml",
434 "dom/events/test/test_bug415498.xhtml",
435 "dom/events/test/test_bug602962.xhtml",
436 "dom/events/test/test_bug617528.xhtml",
437 "dom/events/test/test_bug679494.xhtml",
438 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
439 "dom/indexedDB/test/test_wrappedArray.xhtml",
440 "dom/ipc/test.xhtml",
441 "dom/ipc/tests/test_process_error.xhtml",
442 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
443 "dom/security/test/general/test_bug1277803.xhtml",
444 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
445 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
446 "dom/system/tests/test_constants.xhtml",
447 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
448 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
449 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
450 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
451 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
452 "dom/tests/mochitest/chrome/window_focus.xhtml",
453 "dom/url/tests/test_bug883784.xhtml",
454 "dom/workers/test/test_WorkerDebugger.xhtml",
455 "dom/workers/test/test_WorkerDebugger_console.xhtml",
456 "dom/workers/test/test_fileReadSlice.xhtml",
457 "dom/workers/test/test_fileReaderSync.xhtml",
458 "dom/workers/test/test_fileSlice.xhtml",
461 "mozilla/no-useless-parameters": "off",
462 "mozilla/no-useless-removeEventListener": "off",
463 "mozilla/use-chromeutils-generateqi": "off",
464 "mozilla/use-services": "off",
466 "no-array-constructor": "off",
470 "no-lone-blocks": "off",
471 "no-redeclare": "off",
473 "no-throw-literal": "off",
474 "no-unsanitized/method": "off",
475 "no-useless-return": "off",
476 "object-shorthand": "off",
480 files: ["dom/**", "netwerk/**"],
482 "mozilla/prefer-boolean-length-check": "off",
486 // Rules of Hooks broadly checks for camelCase "use" identifiers, so
487 // enable only for paths actually using React to avoid false positives.
488 extends: ["plugin:react-hooks/recommended"],
490 "browser/components/newtab/**",
491 "browser/components/pocket/**",
496 // Turn off the osfile rule for osfile.
497 files: ["toolkit/components/osfile/**"],
499 "mozilla/reject-osfile": "off",