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 "caps/tests/unit/test_site_origin.js",
187 "chrome/test/unit/test_no_remote_registration.js",
188 "extensions/permissions/**",
189 "image/test/unit/**",
190 "intl/uconv/tests/unit/test_bug317216.js",
191 "intl/uconv/tests/unit/test_bug340714.js",
192 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
193 "modules/libjar/zipwriter/test/unit/test_alignment.js",
194 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
195 "modules/libjar/zipwriter/test/unit/test_storedata.js",
196 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
197 "modules/libpref/test/unit/test_changeType.js",
198 "modules/libpref/test/unit/test_dirtyPrefs.js",
199 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
200 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
201 "xpcom/tests/unit/test_hidden_files.js",
202 "xpcom/tests/unit/test_localfile.js",
204 // These are more complicated bugs which may require some in-depth
205 // investigation or different solutions. They are also likely to be
206 // a reasonable size.
207 "browser/components/**",
208 "browser/modules/**",
211 "security/manager/ssl/tests/unit/**",
213 "testing/xpcshell/**",
214 "toolkit/components/**",
215 "toolkit/modules/**",
218 // No declaring variables that are never used
229 ...browserTestConfig,
230 files: browserTestPaths.map(path => `${path}**`),
233 ...removeOverrides(mochitestTestConfig),
234 files: mochitestTestPaths.map(path => `${path}**`),
235 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
238 ...removeOverrides(chromeTestConfig),
239 files: chromeTestPaths.map(path => `${path}**`),
243 // Ideally we wouldn't be using the simpletest env here, but our uses of
244 // js files mean we pick up everything from the global scope, which could
245 // be any one of a number of html files. So we just allow the basics...
246 "mozilla/simpletest": true,
249 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
250 ...chromeTestPaths.map(path => `${path}/**/*.js`),
255 "netwerk/cookie/test/browser/**",
256 "netwerk/test/browser/**",
257 "netwerk/test/mochitests/**",
258 "netwerk/test/unit*/**",
261 "mozilla/no-arbitrary-setTimeout": "off",
262 "mozilla/no-define-cc-etc": "off",
263 "consistent-return": "off",
265 "no-global-assign": "off",
266 "no-nested-ternary": "off",
267 "no-redeclare": "off",
269 "no-throw-literal": "off",
273 files: ["layout/**"],
275 "object-shorthand": "off",
276 "mozilla/avoid-removeChild": "off",
277 "mozilla/consistent-if-bracing": "off",
278 "mozilla/reject-importGlobalProperties": "off",
279 "mozilla/no-arbitrary-setTimeout": "off",
280 "mozilla/no-define-cc-etc": "off",
281 "mozilla/use-chromeutils-generateqi": "off",
282 "mozilla/use-default-preference-values": "off",
283 "mozilla/use-includes-instead-of-indexOf": "off",
284 "mozilla/use-services": "off",
285 "mozilla/use-ownerGlobal": "off",
287 "consistent-return": "off",
288 "no-array-constructor": "off",
290 "no-cond-assign": "off",
291 "no-extra-boolean-cast": "off",
293 "no-func-assign": "off",
294 "no-global-assign": "off",
295 "no-implied-eval": "off",
296 "no-lonely-if": "off",
297 "no-nested-ternary": "off",
298 "no-new-wrappers": "off",
299 "no-redeclare": "off",
300 "no-restricted-globals": "off",
301 "no-return-await": "off",
302 "no-sequences": "off",
303 "no-throw-literal": "off",
304 "no-useless-concat": "off",
306 "no-unreachable": "off",
307 "no-unsanitized/method": "off",
308 "no-unsanitized/property": "off",
309 "no-unsafe-negation": "off",
310 "no-unused-vars": "off",
311 "no-useless-return": "off",
318 "dom/base/test/unit/test_serializers_entities*.js",
319 "dom/base/test/unit_ipc/**",
320 "dom/base/test/jsmodules/**",
329 "dom/media/tests/**",
330 "dom/media/webaudio/**",
331 "dom/media/webrtc/tests/**",
332 "dom/media/webspeech/**",
333 "dom/messagechannel/**",
337 "dom/performance/**",
340 "dom/security/test/cors/**",
341 "dom/security/test/csp/**",
342 "dom/security/test/mixedcontentblocker/**",
343 "dom/serviceworkers/**",
345 "dom/tests/mochitest/**",
356 "dom/ipc/test.xhtml",
359 "consistent-return": "off",
360 "mozilla/avoid-removeChild": "off",
361 "mozilla/consistent-if-bracing": "off",
362 "mozilla/no-arbitrary-setTimeout": "off",
363 "mozilla/no-compare-against-boolean-literals": "off",
364 "mozilla/no-define-cc-etc": "off",
365 "mozilla/reject-importGlobalProperties": "off",
366 "mozilla/use-cc-etc": "off",
367 "mozilla/use-chromeutils-generateqi": "off",
368 "mozilla/use-chromeutils-import": "off",
369 "mozilla/use-includes-instead-of-indexOf": "off",
370 "mozilla/use-ownerGlobal": "off",
371 "mozilla/use-services": "off",
372 "no-array-constructor": "off",
374 "no-cond-assign": "off",
375 "no-control-regex": "off",
376 "no-debugger": "off",
377 "no-else-return": "off",
380 "no-func-assign": "off",
381 "no-global-assign": "off",
382 "no-implied-eval": "off",
383 "no-lone-blocks": "off",
384 "no-lonely-if": "off",
385 "no-nested-ternary": "off",
386 "no-new-object": "off",
387 "no-new-wrappers": "off",
388 "no-redeclare": "off",
389 "no-return-await": "off",
390 "no-restricted-globals": "off",
391 "no-self-assign": "off",
392 "no-self-compare": "off",
393 "no-sequences": "off",
395 "no-shadow-restricted-names": "off",
396 "no-sparse-arrays": "off",
397 "no-throw-literal": "off",
398 "no-unreachable": "off",
399 "no-unsanitized/method": "off",
400 "no-unsanitized/property": "off",
402 "no-unused-vars": "off",
403 "no-useless-call": "off",
404 "no-useless-concat": "off",
405 "no-useless-return": "off",
411 "testing/mochitest/browser-harness.xhtml",
412 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
413 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
414 "testing/mochitest/chrome/test_sanityException.xhtml",
415 "testing/mochitest/chrome/test_sanityException2.xhtml",
416 "testing/mochitest/harness.xhtml",
419 "dot-notation": "off",
420 "object-shorthand": "off",
421 "mozilla/use-services": "off",
422 "mozilla/no-compare-against-boolean-literals": "off",
423 "mozilla/no-useless-parameters": "off",
424 "mozilla/no-useless-removeEventListener": "off",
425 "mozilla/use-cc-etc": "off",
426 "consistent-return": "off",
427 "no-fallthrough": "off",
428 "no-nested-ternary": "off",
429 "no-redeclare": "off",
430 "no-sequences": "off",
432 "no-throw-literal": "off",
434 "no-unsanitized/property": "off",
435 "no-unused-vars": "off",
436 "no-useless-call": "off",
441 "dom/base/test/chrome/file_bug1139964.xhtml",
442 "dom/base/test/chrome/file_bug549682.xhtml",
443 "dom/base/test/chrome/file_bug616841.xhtml",
444 "dom/base/test/chrome/file_bug990812-1.xhtml",
445 "dom/base/test/chrome/file_bug990812-2.xhtml",
446 "dom/base/test/chrome/file_bug990812-3.xhtml",
447 "dom/base/test/chrome/file_bug990812-4.xhtml",
448 "dom/base/test/chrome/file_bug990812-5.xhtml",
449 "dom/base/test/chrome/file_bug990812.xhtml",
450 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
451 "dom/base/test/chrome/test_bug339494.xhtml",
452 "dom/base/test/chrome/test_bug429785.xhtml",
453 "dom/base/test/chrome/test_bug467123.xhtml",
454 "dom/base/test/chrome/test_bug683852.xhtml",
455 "dom/base/test/chrome/test_bug780529.xhtml",
456 "dom/base/test/chrome/test_bug800386.xhtml",
457 "dom/base/test/chrome/test_bug884693.xhtml",
458 "dom/base/test/chrome/test_document-element-inserted.xhtml",
459 "dom/base/test/chrome/test_domparsing.xhtml",
460 "dom/base/test/chrome/title_window.xhtml",
461 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
462 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
463 "dom/base/test/test_domrequesthelper.xhtml",
464 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
465 "dom/console/tests/test_jsm.xhtml",
466 "dom/events/test/test_bug1412775.xhtml",
467 "dom/events/test/test_bug336682_2.xhtml",
468 "dom/events/test/test_bug415498.xhtml",
469 "dom/events/test/test_bug602962.xhtml",
470 "dom/events/test/test_bug617528.xhtml",
471 "dom/events/test/test_bug679494.xhtml",
472 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
473 "dom/indexedDB/test/test_wrappedArray.xhtml",
474 "dom/ipc/test.xhtml",
475 "dom/ipc/tests/test_process_error.xhtml",
476 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
477 "dom/security/test/general/test_bug1277803.xhtml",
478 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
479 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
480 "dom/system/tests/test_constants.xhtml",
481 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
482 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
483 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
484 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
485 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
486 "dom/tests/mochitest/chrome/window_focus.xhtml",
487 "dom/url/tests/test_bug883784.xhtml",
488 "dom/workers/test/test_WorkerDebugger.xhtml",
489 "dom/workers/test/test_WorkerDebugger_console.xhtml",
490 "dom/workers/test/test_fileReadSlice.xhtml",
491 "dom/workers/test/test_fileReaderSync.xhtml",
492 "dom/workers/test/test_fileSlice.xhtml",
495 "mozilla/no-useless-parameters": "off",
496 "mozilla/no-useless-removeEventListener": "off",
497 "mozilla/use-chromeutils-generateqi": "off",
498 "mozilla/use-services": "off",
500 "no-array-constructor": "off",
504 "no-lone-blocks": "off",
505 "no-redeclare": "off",
507 "no-throw-literal": "off",
508 "no-unsanitized/method": "off",
509 "no-useless-return": "off",
510 "object-shorthand": "off",
519 "editor/libeditor/tests/**",
520 "editor/spellchecker/tests/test_bug338427.html",
522 "image/test/browser/browser_image.js",
529 "security/manager/**",
531 "storage/test/unit/test_vacuum.js",
532 "taskcluster/docker/periodic-updates/scripts/**",
535 "widget/tests/test_assign_event_data.html",
538 "mozilla/prefer-boolean-length-check": "off",
542 // TODO: Bug 1609271 Fix all violations for ChromeUtils.import(..., null)
544 "browser/base/content/test/sync/browser_fxa_web_channel.js",
545 "browser/components/migration/tests/unit/test_Edge_db_migration.js",
546 "browser/components/translation/test/unit/test_cld2.js",
547 "browser/extensions/formautofill/test/unit/test_sync.js",
548 "devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js",
549 "dom/ipc/tests/browser_memory_distribution_telemetry.js",
550 "dom/push/test/xpcshell/head.js",
551 "dom/push/test/xpcshell/test_broadcast_success.js",
552 "dom/push/test/xpcshell/test_crypto.js",
553 "toolkit/components/cloudstorage/tests/unit/test_cloudstorage.js",
554 "toolkit/components/crashes/tests/xpcshell/test_crash_manager.js",
555 "toolkit/components/crashes/tests/xpcshell/test_crash_service.js",
556 "toolkit/components/crashes/tests/xpcshell/test_crash_store.js",
557 "toolkit/components/featuregates/test/unit/test_FeatureGate.js",
558 "toolkit/components/normandy/test/browser/browser_actions_ShowHeartbeatAction.js",
559 "toolkit/modules/subprocess/test/xpcshell/test_subprocess.js",
560 "toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
561 "toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
562 "toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
563 "toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js",
564 "toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js",
565 "toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js",
566 "toolkit/mozapps/extensions/test/xpcshell/test_signed_updatepref.js",
567 "toolkit/mozapps/extensions/test/xpcshell/test_signed_verify.js",
568 "toolkit/mozapps/extensions/test/xpcshell/test_webextension_events.js",
569 "toolkit/mozapps/extensions/test/xpcshell/test_XPIStates.js",
572 "mozilla/reject-chromeutils-import-params": "warn",