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 = ["**/test*/unit*/**/", "**/test*/xpcshell/**/"];
26 const browserTestPaths = ["**/test*/**/browser*/"];
28 const mochitestTestPaths = [
29 // Note: we do not want to match testing/mochitest as that would apply
30 // too many globals for that directory.
32 "**/tests/mochitest/",
33 "**/test/mochitests/",
34 "testing/mochitest/tests/SimpleTest/",
35 "testing/mochitest/tests/Harness_sanity/",
38 const chromeTestPaths = ["**/test*/chrome/"];
40 const ignorePatterns = [
43 path.join(__dirname, "tools", "rewriting", "ThirdPartyPaths.txt")
49 path.join(__dirname, "devtools", "client", "debugger", ".eslintignore")
53 .filter(p => p && !p.startsWith("#"))
54 .map(p => `devtools/client/debugger/${p}`),
58 parser: "@babel/eslint-parser",
62 configFile: path.join(__dirname, ".babel-eslint.rc.js"),
66 // Ignore eslint configurations in parent directories.
68 // New rules and configurations should generally be added in
69 // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
70 // allow external repositories that use the plugin to pick them up as well.
71 extends: ["plugin:mozilla/recommended"],
75 // All .eslintrc.js files are in the node environment, so turn that
77 // https://github.com/eslint/eslint/issues/13008
78 files: [".eslintrc.js"],
94 "valid-jsdoc": "warn",
95 "no-redeclare": "warn",
96 "no-unused-vars": "warn",
97 "no-fallthrough": "warn",
98 "mozilla/no-aArgs": "warn",
99 "block-scoped-var": "warn",
100 "no-control-regex": "warn",
101 "no-throw-literal": "warn",
102 "no-useless-concat": "warn",
103 "consistent-return": "warn",
104 "mozilla/use-cc-etc": "warn",
105 "no-use-before-define": "warn",
106 "mozilla/use-services": "warn",
107 "mozilla/use-includes-instead-of-indexOf": "warn",
108 "mozilla/no-compare-against-boolean-literals": "warn",
109 "mozilla/reject-importGlobalProperties": "warn",
110 "mozilla/var-only-at-top-level": "warn",
119 "js/src/builtin/**/*.js",
120 "js/src/shell/**/*.js",
123 // Curly brackets are required for all the tree via recommended.js,
124 // however these files aren't auto-fixable at the moment.
129 // TODO: Bug 1515949. Enable no-undef for gfx/
130 files: "gfx/layers/apz/test/mochitest/**",
136 ...removeOverrides(xpcshellTestConfig),
137 files: xpcshellTestPaths.map(path => `${path}**`),
138 excludedFiles: "devtools/**",
141 // If it is an xpcshell head file, we turn off global unused variable checks, as it
142 // would require searching the other test files to know if they are used or not.
143 // This would be expensive and slow, and it isn't worth it for head files.
144 // We could get developers to declare as exported, but that doesn't seem worth it.
145 files: xpcshellTestPaths.map(path => `${path}head*.js`),
157 // This section enables warning of no-unused-vars globally for all test*.js
158 // files in xpcshell test paths.
159 // These are turned into errors with selected exclusions in the next
161 // Bug 1612907: This section should go away once the exclusions are removed
162 // from the following section.
163 files: xpcshellTestPaths.map(path => `${path}test*.js`),
165 // No declaring variables that are never used
176 // This section makes global issues with no-unused-vars be reported as
177 // errors - except for the excluded lists which are being fixed in the
178 // dependencies of bug 1612907.
179 files: xpcshellTestPaths.map(path => `${path}test*.js`),
181 // These are suitable as good first bugs, take one or two related lines
183 "caps/tests/unit/test_origin.js",
184 "caps/tests/unit/test_site_origin.js",
185 "chrome/test/unit/test_no_remote_registration.js",
186 "extensions/permissions/**",
187 "image/test/unit/**",
188 "intl/uconv/tests/unit/test_bug317216.js",
189 "intl/uconv/tests/unit/test_bug340714.js",
190 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
191 "modules/libjar/zipwriter/test/unit/test_alignment.js",
192 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
193 "modules/libjar/zipwriter/test/unit/test_storedata.js",
194 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
195 "modules/libpref/test/unit/test_changeType.js",
196 "modules/libpref/test/unit/test_dirtyPrefs.js",
197 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
198 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
199 "xpcom/tests/unit/test_hidden_files.js",
200 "xpcom/tests/unit/test_localfile.js",
202 // These are more complicated bugs which may require some in-depth
203 // investigation or different solutions. They are also likely to be
204 // a reasonable size.
205 "browser/components/**",
206 "browser/modules/**",
209 "security/manager/ssl/tests/unit/**",
211 "testing/xpcshell/**",
212 "toolkit/components/**",
213 "toolkit/modules/**",
216 // No declaring variables that are never used
227 ...browserTestConfig,
228 files: browserTestPaths.map(path => `${path}**`),
231 ...removeOverrides(mochitestTestConfig),
232 files: mochitestTestPaths.map(path => `${path}**`),
233 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
236 ...removeOverrides(chromeTestConfig),
237 files: chromeTestPaths.map(path => `${path}**`),
241 // Ideally we wouldn't be using the simpletest env here, but our uses of
242 // js files mean we pick up everything from the global scope, which could
243 // be any one of a number of html files. So we just allow the basics...
244 "mozilla/simpletest": true,
247 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
248 ...chromeTestPaths.map(path => `${path}/**/*.js`),
253 "netwerk/cookie/test/browser/**",
254 "netwerk/test/browser/**",
255 "netwerk/test/mochitests/**",
256 "netwerk/test/unit*/**",
259 "mozilla/no-arbitrary-setTimeout": "off",
260 "mozilla/no-define-cc-etc": "off",
261 "mozilla/use-services": "off",
262 "consistent-return": "off",
264 "no-global-assign": "off",
265 "no-nested-ternary": "off",
266 "no-redeclare": "off",
268 "no-throw-literal": "off",
272 files: ["layout/**"],
274 "object-shorthand": "off",
275 "mozilla/avoid-removeChild": "off",
276 "mozilla/consistent-if-bracing": "off",
277 "mozilla/reject-importGlobalProperties": "off",
278 "mozilla/no-arbitrary-setTimeout": "off",
279 "mozilla/no-define-cc-etc": "off",
280 "mozilla/use-chromeutils-generateqi": "off",
281 "mozilla/use-default-preference-values": "off",
282 "mozilla/use-includes-instead-of-indexOf": "off",
283 "mozilla/use-services": "off",
284 "mozilla/use-ownerGlobal": "off",
286 "consistent-return": "off",
287 "no-array-constructor": "off",
289 "no-cond-assign": "off",
290 "no-extra-boolean-cast": "off",
292 "no-func-assign": "off",
293 "no-global-assign": "off",
294 "no-implied-eval": "off",
295 "no-lonely-if": "off",
296 "no-nested-ternary": "off",
297 "no-new-wrappers": "off",
298 "no-redeclare": "off",
299 "no-restricted-globals": "off",
300 "no-return-await": "off",
301 "no-sequences": "off",
302 "no-throw-literal": "off",
303 "no-useless-concat": "off",
305 "no-unreachable": "off",
306 "no-unsanitized/method": "off",
307 "no-unsanitized/property": "off",
308 "no-unsafe-negation": "off",
309 "no-unused-vars": "off",
310 "no-useless-return": "off",
317 "dom/base/test/unit/test_serializers_entities*.js",
318 "dom/base/test/unit_ipc/**",
319 "dom/base/test/jsmodules/**",
328 "dom/media/tests/**",
329 "dom/media/webaudio/**",
330 "dom/media/webrtc/tests/**",
331 "dom/media/webspeech/**",
332 "dom/messagechannel/**",
336 "dom/performance/**",
339 "dom/security/test/cors/**",
340 "dom/security/test/csp/**",
341 "dom/security/test/mixedcontentblocker/**",
342 "dom/serviceworkers/**",
344 "dom/tests/mochitest/**",
355 "dom/ipc/test.xhtml",
358 "consistent-return": "off",
359 "mozilla/avoid-removeChild": "off",
360 "mozilla/consistent-if-bracing": "off",
361 "mozilla/no-arbitrary-setTimeout": "off",
362 "mozilla/no-compare-against-boolean-literals": "off",
363 "mozilla/no-define-cc-etc": "off",
364 "mozilla/reject-importGlobalProperties": "off",
365 "mozilla/use-cc-etc": "off",
366 "mozilla/use-chromeutils-generateqi": "off",
367 "mozilla/use-chromeutils-import": "off",
368 "mozilla/use-includes-instead-of-indexOf": "off",
369 "mozilla/use-ownerGlobal": "off",
370 "mozilla/use-services": "off",
371 "no-array-constructor": "off",
373 "no-cond-assign": "off",
374 "no-control-regex": "off",
375 "no-debugger": "off",
376 "no-else-return": "off",
379 "no-func-assign": "off",
380 "no-global-assign": "off",
381 "no-implied-eval": "off",
382 "no-lone-blocks": "off",
383 "no-lonely-if": "off",
384 "no-nested-ternary": "off",
385 "no-new-object": "off",
386 "no-new-wrappers": "off",
387 "no-redeclare": "off",
388 "no-return-await": "off",
389 "no-restricted-globals": "off",
390 "no-self-assign": "off",
391 "no-self-compare": "off",
392 "no-sequences": "off",
394 "no-shadow-restricted-names": "off",
395 "no-sparse-arrays": "off",
396 "no-throw-literal": "off",
397 "no-unreachable": "off",
398 "no-unsanitized/method": "off",
399 "no-unsanitized/property": "off",
401 "no-unused-vars": "off",
402 "no-useless-call": "off",
403 "no-useless-concat": "off",
404 "no-useless-return": "off",
410 "testing/mochitest/browser-harness.xhtml",
411 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
412 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
413 "testing/mochitest/chrome/test_sanityException.xhtml",
414 "testing/mochitest/chrome/test_sanityException2.xhtml",
415 "testing/mochitest/harness.xhtml",
418 "dot-notation": "off",
419 "object-shorthand": "off",
420 "mozilla/use-services": "off",
421 "mozilla/no-compare-against-boolean-literals": "off",
422 "mozilla/no-useless-parameters": "off",
423 "mozilla/no-useless-removeEventListener": "off",
424 "mozilla/use-cc-etc": "off",
425 "consistent-return": "off",
426 "no-fallthrough": "off",
427 "no-nested-ternary": "off",
428 "no-redeclare": "off",
429 "no-sequences": "off",
431 "no-throw-literal": "off",
433 "no-unsanitized/property": "off",
434 "no-unused-vars": "off",
435 "no-useless-call": "off",
440 "dom/base/test/chrome/file_bug1139964.xhtml",
441 "dom/base/test/chrome/file_bug549682.xhtml",
442 "dom/base/test/chrome/file_bug616841.xhtml",
443 "dom/base/test/chrome/file_bug990812-1.xhtml",
444 "dom/base/test/chrome/file_bug990812-2.xhtml",
445 "dom/base/test/chrome/file_bug990812-3.xhtml",
446 "dom/base/test/chrome/file_bug990812-4.xhtml",
447 "dom/base/test/chrome/file_bug990812-5.xhtml",
448 "dom/base/test/chrome/file_bug990812.xhtml",
449 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
450 "dom/base/test/chrome/test_bug339494.xhtml",
451 "dom/base/test/chrome/test_bug429785.xhtml",
452 "dom/base/test/chrome/test_bug467123.xhtml",
453 "dom/base/test/chrome/test_bug683852.xhtml",
454 "dom/base/test/chrome/test_bug780529.xhtml",
455 "dom/base/test/chrome/test_bug800386.xhtml",
456 "dom/base/test/chrome/test_bug884693.xhtml",
457 "dom/base/test/chrome/test_document-element-inserted.xhtml",
458 "dom/base/test/chrome/test_domparsing.xhtml",
459 "dom/base/test/chrome/test_fileconstructor.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",
509 "no-unsanitized/method": "off",
510 "no-unused-vars": "off",
511 "no-useless-return": "off",
512 "object-shorthand": "off",
521 "editor/libeditor/tests/**",
522 "editor/spellchecker/tests/test_bug338427.html",
524 "image/test/browser/browser_image.js",
531 "security/manager/**",
533 "storage/test/unit/test_vacuum.js",
534 "taskcluster/docker/periodic-updates/scripts/**",
537 "widget/tests/test_assign_event_data.html",
540 "mozilla/prefer-boolean-length-check": "off",
544 // TODO: Bug 1609271 Fix all violations for ChromeUtils.import(..., null)
546 "browser/base/content/test/forms/head.js",
547 "browser/base/content/test/general/browser_datachoices_notification.js",
548 "browser/base/content/test/sync/browser_fxa_web_channel.js",
549 "browser/base/content/test/webextensions/head.js",
550 "browser/components/customizableui/test/browser_1042100_default_placements_update.js",
551 "browser/components/customizableui/test/browser_1096763_seen_widgets_post_reset.js",
552 "browser/components/customizableui/test/browser_1161838_inserted_new_default_buttons.js",
553 "browser/components/customizableui/test/browser_989338_saved_placements_not_resaved.js",
554 "browser/components/customizableui/test/browser_currentset_post_reset.js",
555 "browser/components/customizableui/test/browser_panel_keyboard_navigation.js",
556 "browser/components/customizableui/test/browser_proton_toolbar_hide_toolbarbuttons.js",
557 "browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js",
558 "browser/components/enterprisepolicies/tests/xpcshell/head.js",
559 "browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js",
560 "browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js",
561 "browser/components/migration/tests/unit/test_Edge_db_migration.js",
562 "browser/components/translation/test/unit/test_cld2.js",
563 "browser/extensions/formautofill/test/unit/test_sync.js",
564 "browser/extensions/report-site-issue/test/browser/head.js",
565 "devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js",
566 "dom/ipc/tests/browser_memory_distribution_telemetry.js",
567 "dom/push/test/xpcshell/head.js",
568 "dom/push/test/xpcshell/test_broadcast_success.js",
569 "dom/push/test/xpcshell/test_crypto.js",
570 "security/manager/ssl/RemoteSecuritySettings.jsm",
571 "services/common/tests/unit/head_helpers.js",
572 "services/common/tests/unit/test_uptake_telemetry.js",
573 "services/fxaccounts/tests/xpcshell/test_accounts.js",
574 "services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js",
575 "services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js",
576 "services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js",
577 "services/fxaccounts/tests/xpcshell/test_oauth_tokens.js",
578 "services/fxaccounts/tests/xpcshell/test_web_channel.js",
579 "services/sync/modules-testing/utils.js",
580 "services/sync/tests/unit/test_postqueue.js",
581 "toolkit/components/cloudstorage/tests/unit/test_cloudstorage.js",
582 "toolkit/components/crashes/tests/xpcshell/test_crash_manager.js",
583 "toolkit/components/crashes/tests/xpcshell/test_crash_service.js",
584 "toolkit/components/crashes/tests/xpcshell/test_crash_store.js",
585 "toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm",
586 "toolkit/components/featuregates/test/unit/test_FeatureGate.js",
587 "toolkit/components/normandy/test/browser/browser_actions_ShowHeartbeatAction.js",
588 "toolkit/components/osfile/modules/osfile_async_front.jsm",
589 "toolkit/components/osfile/modules/osfile_native.jsm",
590 "toolkit/components/osfile/tests/xpcshell/test_osfile_kill.js",
591 "toolkit/components/processsingleton/MainProcessSingleton.jsm",
592 "toolkit/modules/subprocess/test/xpcshell/test_subprocess.js",
593 "toolkit/modules/tests/xpcshell/test_GMPInstallManager.js",
594 "toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
595 "toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
596 "toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
597 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js",
598 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_regexp_split.js",
599 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js",
600 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_telemetry.js",
601 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklistchange.js",
602 "toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js",
603 "toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js",
604 "toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js",
605 "toolkit/mozapps/extensions/test/xpcshell/test_signed_updatepref.js",
606 "toolkit/mozapps/extensions/test/xpcshell/test_signed_verify.js",
607 "toolkit/mozapps/extensions/test/xpcshell/test_webextension.js",
608 "toolkit/mozapps/extensions/test/xpcshell/test_webextension_events.js",
609 "toolkit/mozapps/extensions/test/xpcshell/test_XPIStates.js",
612 "mozilla/reject-chromeutils-import-params": "off",