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"],
102 "no-redeclare": "warn",
103 "no-unused-vars": "warn",
104 "no-fallthrough": "warn",
105 "no-control-regex": "warn",
106 "no-throw-literal": "warn",
107 "no-useless-concat": "warn",
108 "consistent-return": "warn",
109 "mozilla/use-cc-etc": "warn",
110 "mozilla/use-services": "warn",
111 "mozilla/use-includes-instead-of-indexOf": "warn",
112 "mozilla/no-compare-against-boolean-literals": "warn",
121 "js/src/builtin/**/*.js",
122 "js/src/shell/**/*.js",
125 // Curly brackets are required for all the tree via recommended.js,
126 // however these files aren't auto-fixable at the moment.
131 // TODO: Bug 1515949. Enable no-undef for gfx/
132 files: "gfx/layers/apz/test/mochitest/**",
138 ...removeOverrides(xpcshellTestConfig),
139 files: xpcshellTestPaths.map(path => `${path}**`),
140 excludedFiles: "devtools/**",
143 // If it is an xpcshell head file, we turn off global unused variable checks, as it
144 // would require searching the other test files to know if they are used or not.
145 // This would be expensive and slow, and it isn't worth it for head files.
146 // We could get developers to declare as exported, but that doesn't seem worth it.
147 files: xpcshellTestPaths.map(path => `${path}head*.js`),
159 // This section enables warning of no-unused-vars globally for all test*.js
160 // files in xpcshell test paths.
161 // These are turned into errors with selected exclusions in the next
163 // Bug 1612907: This section should go away once the exclusions are removed
164 // from the following section.
165 files: xpcshellTestPaths.map(path => `${path}test*.js`),
167 // No declaring variables that are never used
178 // This section makes global issues with no-unused-vars be reported as
179 // errors - except for the excluded lists which are being fixed in the
180 // dependencies of bug 1612907.
181 files: xpcshellTestPaths.map(path => `${path}test*.js`),
183 // These are suitable as good first bugs, take one or two related lines
185 "caps/tests/unit/test_origin.js",
186 "extensions/permissions/**",
187 "image/test/unit/**",
188 "intl/uconv/tests/unit/test_bug340714.js",
189 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
190 "modules/libjar/zipwriter/test/unit/test_alignment.js",
191 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
192 "modules/libjar/zipwriter/test/unit/test_storedata.js",
193 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
194 "modules/libpref/test/unit/test_dirtyPrefs.js",
195 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
196 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
198 // These are more complicated bugs which may require some in-depth
199 // investigation or different solutions. They are also likely to be
200 // a reasonable size.
201 "browser/components/**",
202 "browser/modules/**",
205 "security/manager/ssl/tests/unit/**",
207 "testing/xpcshell/**",
208 "toolkit/components/**",
209 "toolkit/modules/**",
212 // No declaring variables that are never used
223 ...browserTestConfig,
224 files: browserTestPaths.map(path => `${path}**`),
227 ...removeOverrides(mochitestTestConfig),
228 files: mochitestTestPaths.map(path => `${path}**`),
229 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
232 ...removeOverrides(chromeTestConfig),
233 files: chromeTestPaths.map(path => `${path}**`),
237 // Ideally we wouldn't be using the simpletest env here, but our uses of
238 // js files mean we pick up everything from the global scope, which could
239 // be any one of a number of html files. So we just allow the basics...
240 "mozilla/simpletest": true,
243 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
244 ...chromeTestPaths.map(path => `${path}/**/*.js`),
249 "netwerk/cookie/test/browser/**",
250 "netwerk/test/browser/**",
251 "netwerk/test/mochitests/**",
252 "netwerk/test/unit*/**",
255 "mozilla/no-arbitrary-setTimeout": "off",
256 "mozilla/no-define-cc-etc": "off",
257 "consistent-return": "off",
259 "no-global-assign": "off",
260 "no-nested-ternary": "off",
261 "no-redeclare": "off",
263 "no-throw-literal": "off",
267 files: ["layout/**"],
269 "object-shorthand": "off",
270 "mozilla/avoid-removeChild": "off",
271 "mozilla/consistent-if-bracing": "off",
272 "mozilla/reject-importGlobalProperties": "off",
273 "mozilla/no-arbitrary-setTimeout": "off",
274 "mozilla/no-define-cc-etc": "off",
275 "mozilla/use-chromeutils-generateqi": "off",
276 "mozilla/use-default-preference-values": "off",
277 "mozilla/use-includes-instead-of-indexOf": "off",
278 "mozilla/use-services": "off",
279 "mozilla/use-ownerGlobal": "off",
281 "consistent-return": "off",
282 "no-array-constructor": "off",
284 "no-cond-assign": "off",
285 "no-extra-boolean-cast": "off",
287 "no-func-assign": "off",
288 "no-global-assign": "off",
289 "no-implied-eval": "off",
290 "no-lonely-if": "off",
291 "no-nested-ternary": "off",
292 "no-new-wrappers": "off",
293 "no-redeclare": "off",
294 "no-restricted-globals": "off",
295 "no-return-await": "off",
296 "no-sequences": "off",
297 "no-throw-literal": "off",
298 "no-useless-concat": "off",
300 "no-unreachable": "off",
301 "no-unsanitized/method": "off",
302 "no-unsanitized/property": "off",
303 "no-unsafe-negation": "off",
304 "no-unused-vars": "off",
305 "no-useless-return": "off",
312 "dom/base/test/unit/test_serializers_entities*.js",
313 "dom/base/test/unit_ipc/**",
314 "dom/base/test/jsmodules/**",
323 "dom/media/tests/**",
324 "dom/media/webaudio/**",
325 "dom/media/webrtc/tests/**",
326 "dom/media/webspeech/**",
327 "dom/messagechannel/**",
331 "dom/performance/**",
333 "dom/quota/test/browser/**",
334 "dom/quota/test/common/**",
335 "dom/quota/test/mochitest/**",
336 "dom/quota/test/xpcshell/**",
337 "dom/security/test/cors/**",
338 "dom/security/test/csp/**",
339 "dom/security/test/mixedcontentblocker/**",
340 "dom/serviceworkers/**",
342 "dom/tests/mochitest/**",
353 "dom/ipc/test.xhtml",
356 "consistent-return": "off",
357 "mozilla/avoid-removeChild": "off",
358 "mozilla/consistent-if-bracing": "off",
359 "mozilla/no-arbitrary-setTimeout": "off",
360 "mozilla/no-compare-against-boolean-literals": "off",
361 "mozilla/no-define-cc-etc": "off",
362 "mozilla/reject-importGlobalProperties": "off",
363 "mozilla/use-cc-etc": "off",
364 "mozilla/use-chromeutils-generateqi": "off",
365 "mozilla/use-includes-instead-of-indexOf": "off",
366 "mozilla/use-ownerGlobal": "off",
367 "mozilla/use-services": "off",
368 "no-array-constructor": "off",
370 "no-cond-assign": "off",
371 "no-control-regex": "off",
372 "no-debugger": "off",
373 "no-else-return": "off",
376 "no-func-assign": "off",
377 "no-global-assign": "off",
378 "no-implied-eval": "off",
379 "no-lone-blocks": "off",
380 "no-lonely-if": "off",
381 "no-nested-ternary": "off",
382 "no-new-object": "off",
383 "no-new-wrappers": "off",
384 "no-redeclare": "off",
385 "no-return-await": "off",
386 "no-restricted-globals": "off",
387 "no-self-assign": "off",
388 "no-self-compare": "off",
389 "no-sequences": "off",
391 "no-shadow-restricted-names": "off",
392 "no-sparse-arrays": "off",
393 "no-throw-literal": "off",
394 "no-unreachable": "off",
395 "no-unsanitized/method": "off",
396 "no-unsanitized/property": "off",
398 "no-unused-vars": "off",
399 "no-useless-call": "off",
400 "no-useless-concat": "off",
401 "no-useless-return": "off",
407 "testing/mochitest/browser-harness.xhtml",
408 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
409 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
410 "testing/mochitest/chrome/test_sanityException.xhtml",
411 "testing/mochitest/chrome/test_sanityException2.xhtml",
412 "testing/mochitest/harness.xhtml",
415 "dot-notation": "off",
416 "object-shorthand": "off",
417 "mozilla/use-services": "off",
418 "mozilla/no-compare-against-boolean-literals": "off",
419 "mozilla/no-useless-parameters": "off",
420 "mozilla/no-useless-removeEventListener": "off",
421 "mozilla/use-cc-etc": "off",
422 "consistent-return": "off",
423 "no-fallthrough": "off",
424 "no-nested-ternary": "off",
425 "no-redeclare": "off",
426 "no-sequences": "off",
428 "no-throw-literal": "off",
430 "no-unsanitized/property": "off",
431 "no-unused-vars": "off",
432 "no-useless-call": "off",
437 "dom/base/test/chrome/file_bug1139964.xhtml",
438 "dom/base/test/chrome/file_bug549682.xhtml",
439 "dom/base/test/chrome/file_bug616841.xhtml",
440 "dom/base/test/chrome/file_bug990812-1.xhtml",
441 "dom/base/test/chrome/file_bug990812-2.xhtml",
442 "dom/base/test/chrome/file_bug990812-3.xhtml",
443 "dom/base/test/chrome/file_bug990812-4.xhtml",
444 "dom/base/test/chrome/file_bug990812-5.xhtml",
445 "dom/base/test/chrome/file_bug990812.xhtml",
446 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
447 "dom/base/test/chrome/test_bug339494.xhtml",
448 "dom/base/test/chrome/test_bug429785.xhtml",
449 "dom/base/test/chrome/test_bug467123.xhtml",
450 "dom/base/test/chrome/test_bug683852.xhtml",
451 "dom/base/test/chrome/test_bug780529.xhtml",
452 "dom/base/test/chrome/test_bug800386.xhtml",
453 "dom/base/test/chrome/test_bug884693.xhtml",
454 "dom/base/test/chrome/test_document-element-inserted.xhtml",
455 "dom/base/test/chrome/test_domparsing.xhtml",
456 "dom/base/test/chrome/title_window.xhtml",
457 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
458 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
459 "dom/base/test/test_domrequesthelper.xhtml",
460 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
461 "dom/console/tests/test_jsm.xhtml",
462 "dom/events/test/test_bug1412775.xhtml",
463 "dom/events/test/test_bug336682_2.xhtml",
464 "dom/events/test/test_bug415498.xhtml",
465 "dom/events/test/test_bug602962.xhtml",
466 "dom/events/test/test_bug617528.xhtml",
467 "dom/events/test/test_bug679494.xhtml",
468 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
469 "dom/indexedDB/test/test_wrappedArray.xhtml",
470 "dom/ipc/test.xhtml",
471 "dom/ipc/tests/test_process_error.xhtml",
472 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
473 "dom/security/test/general/test_bug1277803.xhtml",
474 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
475 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
476 "dom/system/tests/test_constants.xhtml",
477 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
478 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
479 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
480 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
481 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
482 "dom/tests/mochitest/chrome/window_focus.xhtml",
483 "dom/url/tests/test_bug883784.xhtml",
484 "dom/workers/test/test_WorkerDebugger.xhtml",
485 "dom/workers/test/test_WorkerDebugger_console.xhtml",
486 "dom/workers/test/test_fileReadSlice.xhtml",
487 "dom/workers/test/test_fileReaderSync.xhtml",
488 "dom/workers/test/test_fileSlice.xhtml",
491 "mozilla/no-useless-parameters": "off",
492 "mozilla/no-useless-removeEventListener": "off",
493 "mozilla/use-chromeutils-generateqi": "off",
494 "mozilla/use-services": "off",
496 "no-array-constructor": "off",
500 "no-lone-blocks": "off",
501 "no-redeclare": "off",
503 "no-throw-literal": "off",
504 "no-unsanitized/method": "off",
505 "no-useless-return": "off",
506 "object-shorthand": "off",
515 "editor/libeditor/tests/**",
516 "editor/spellchecker/tests/test_bug338427.html",
518 "image/test/browser/browser_image.js",
525 "security/manager/**",
527 "storage/test/unit/test_vacuum.js",
528 "taskcluster/docker/periodic-updates/scripts/**",
531 "widget/tests/test_assign_event_data.html",
534 "mozilla/prefer-boolean-length-check": "off",
538 // Rules of Hooks broadly checks for camelCase "use" identifiers, so
539 // enable only for paths actually using React to avoid false positives.
540 extends: ["plugin:react-hooks/recommended"],
542 "browser/components/newtab/**",
543 "browser/components/pocket/**",