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"],
90 "js/src/builtin/**/*.js",
91 "js/src/shell/**/*.js",
94 // Curly brackets are required for all the tree via recommended.js,
95 // however these files aren't auto-fixable at the moment.
100 // TODO: Bug 1515949. Enable no-undef for gfx/
101 files: "gfx/layers/apz/test/mochitest/**",
107 ...removeOverrides(xpcshellTestConfig),
108 files: xpcshellTestPaths.map(path => `${path}**`),
109 excludedFiles: "devtools/**",
112 // If it is an xpcshell head file, we turn off global unused variable checks, as it
113 // would require searching the other test files to know if they are used or not.
114 // This would be expensive and slow, and it isn't worth it for head files.
115 // We could get developers to declare as exported, but that doesn't seem worth it.
116 files: xpcshellTestPaths.map(path => `${path}head*.js`),
128 // This section enables warning of no-unused-vars globally for all test*.js
129 // files in xpcshell test paths.
130 // These are turned into errors with selected exclusions in the next
132 // Bug 1612907: This section should go away once the exclusions are removed
133 // from the following section.
134 files: xpcshellTestPaths.map(path => `${path}test*.js`),
136 // No declaring variables that are never used
147 // This section makes global issues with no-unused-vars be reported as
148 // errors - except for the excluded lists which are being fixed in the
149 // dependencies of bug 1612907.
150 files: xpcshellTestPaths.map(path => `${path}test*.js`),
152 // These are suitable as good first bugs, take one or two related lines
154 "caps/tests/unit/test_origin.js",
155 "caps/tests/unit/test_site_origin.js",
156 "chrome/test/unit/test_no_remote_registration.js",
157 "extensions/permissions/**",
158 "image/test/unit/**",
159 "intl/uconv/tests/unit/test_bug317216.js",
160 "intl/uconv/tests/unit/test_bug340714.js",
161 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
162 "modules/libjar/zipwriter/test/unit/test_alignment.js",
163 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
164 "modules/libjar/zipwriter/test/unit/test_storedata.js",
165 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
166 "modules/libpref/test/unit/test_changeType.js",
167 "modules/libpref/test/unit/test_dirtyPrefs.js",
168 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
169 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
170 "xpcom/tests/unit/test_hidden_files.js",
171 "xpcom/tests/unit/test_localfile.js",
173 // These are more complicated bugs which may require some in-depth
174 // investigation or different solutions. They are also likely to be
175 // a reasonable size.
176 "browser/components/**",
177 "browser/modules/**",
180 "security/manager/ssl/tests/unit/**",
182 "testing/xpcshell/**",
183 "toolkit/components/**",
184 "toolkit/modules/**",
187 // No declaring variables that are never used
198 ...browserTestConfig,
199 files: browserTestPaths.map(path => `${path}**`),
202 ...removeOverrides(mochitestTestConfig),
203 files: mochitestTestPaths.map(path => `${path}**`),
204 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
207 ...removeOverrides(chromeTestConfig),
208 files: chromeTestPaths.map(path => `${path}**`),
212 // Ideally we wouldn't be using the simpletest env here, but our uses of
213 // js files mean we pick up everything from the global scope, which could
214 // be any one of a number of html files. So we just allow the basics...
215 "mozilla/simpletest": true,
218 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
219 ...chromeTestPaths.map(path => `${path}/**/*.js`),
224 "netwerk/cookie/test/browser/**",
225 "netwerk/test/browser/**",
226 "netwerk/test/mochitests/**",
227 "netwerk/test/unit*/**",
230 "mozilla/no-arbitrary-setTimeout": "off",
231 "mozilla/no-define-cc-etc": "off",
232 "mozilla/use-services": "off",
233 "consistent-return": "off",
235 "no-global-assign": "off",
236 "no-nested-ternary": "off",
237 "no-redeclare": "off",
239 "no-throw-literal": "off",
243 files: ["layout/**"],
245 "object-shorthand": "off",
246 "mozilla/avoid-removeChild": "off",
247 "mozilla/consistent-if-bracing": "off",
248 "mozilla/reject-importGlobalProperties": "off",
249 "mozilla/no-arbitrary-setTimeout": "off",
250 "mozilla/no-define-cc-etc": "off",
251 "mozilla/use-chromeutils-generateqi": "off",
252 "mozilla/use-default-preference-values": "off",
253 "mozilla/use-includes-instead-of-indexOf": "off",
254 "mozilla/use-services": "off",
255 "mozilla/use-ownerGlobal": "off",
257 "consistent-return": "off",
258 "no-array-constructor": "off",
260 "no-cond-assign": "off",
261 "no-extra-boolean-cast": "off",
263 "no-func-assign": "off",
264 "no-global-assign": "off",
265 "no-implied-eval": "off",
266 "no-lonely-if": "off",
267 "no-nested-ternary": "off",
268 "no-new-wrappers": "off",
269 "no-redeclare": "off",
270 "no-restricted-globals": "off",
271 "no-return-await": "off",
272 "no-sequences": "off",
273 "no-throw-literal": "off",
274 "no-useless-concat": "off",
276 "no-unreachable": "off",
277 "no-unsanitized/method": "off",
278 "no-unsanitized/property": "off",
279 "no-unsafe-negation": "off",
280 "no-unused-vars": "off",
281 "no-useless-return": "off",
288 "dom/base/test/unit/test_serializers_entities*.js",
289 "dom/base/test/unit_ipc/**",
290 "dom/base/test/jsmodules/**",
299 "dom/media/tests/**",
300 "dom/media/webaudio/**",
301 "dom/media/webrtc/tests/**",
302 "dom/media/webspeech/**",
303 "dom/messagechannel/**",
307 "dom/performance/**",
310 "dom/security/test/cors/**",
311 "dom/security/test/csp/**",
312 "dom/security/test/mixedcontentblocker/**",
313 "dom/serviceworkers/**",
315 "dom/tests/mochitest/**",
326 "dom/ipc/test.xhtml",
329 "consistent-return": "off",
330 "mozilla/avoid-removeChild": "off",
331 "mozilla/consistent-if-bracing": "off",
332 "mozilla/no-arbitrary-setTimeout": "off",
333 "mozilla/no-compare-against-boolean-literals": "off",
334 "mozilla/no-define-cc-etc": "off",
335 "mozilla/reject-importGlobalProperties": "off",
336 "mozilla/use-cc-etc": "off",
337 "mozilla/use-chromeutils-generateqi": "off",
338 "mozilla/use-chromeutils-import": "off",
339 "mozilla/use-includes-instead-of-indexOf": "off",
340 "mozilla/use-ownerGlobal": "off",
341 "mozilla/use-services": "off",
342 "no-array-constructor": "off",
344 "no-cond-assign": "off",
345 "no-control-regex": "off",
346 "no-debugger": "off",
347 "no-else-return": "off",
350 "no-func-assign": "off",
351 "no-global-assign": "off",
352 "no-implied-eval": "off",
353 "no-lone-blocks": "off",
354 "no-lonely-if": "off",
355 "no-nested-ternary": "off",
356 "no-new-object": "off",
357 "no-new-wrappers": "off",
358 "no-redeclare": "off",
359 "no-return-await": "off",
360 "no-restricted-globals": "off",
361 "no-self-assign": "off",
362 "no-self-compare": "off",
363 "no-sequences": "off",
365 "no-shadow-restricted-names": "off",
366 "no-sparse-arrays": "off",
367 "no-throw-literal": "off",
368 "no-unreachable": "off",
369 "no-unsanitized/method": "off",
370 "no-unsanitized/property": "off",
372 "no-unused-vars": "off",
373 "no-useless-call": "off",
374 "no-useless-concat": "off",
375 "no-useless-return": "off",
381 "testing/mochitest/browser-harness.xhtml",
382 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
383 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
384 "testing/mochitest/chrome/test_sanityException.xhtml",
385 "testing/mochitest/chrome/test_sanityException2.xhtml",
386 "testing/mochitest/harness.xhtml",
389 "dot-notation": "off",
390 "object-shorthand": "off",
391 "mozilla/use-services": "off",
392 "mozilla/no-compare-against-boolean-literals": "off",
393 "mozilla/no-useless-parameters": "off",
394 "mozilla/no-useless-removeEventListener": "off",
395 "mozilla/use-cc-etc": "off",
396 "consistent-return": "off",
397 "no-fallthrough": "off",
398 "no-nested-ternary": "off",
399 "no-redeclare": "off",
400 "no-sequences": "off",
402 "no-throw-literal": "off",
404 "no-unsanitized/property": "off",
405 "no-unused-vars": "off",
406 "no-useless-call": "off",
411 "dom/base/test/chrome/file_bug1139964.xhtml",
412 "dom/base/test/chrome/file_bug549682.xhtml",
413 "dom/base/test/chrome/file_bug616841.xhtml",
414 "dom/base/test/chrome/file_bug990812-1.xhtml",
415 "dom/base/test/chrome/file_bug990812-2.xhtml",
416 "dom/base/test/chrome/file_bug990812-3.xhtml",
417 "dom/base/test/chrome/file_bug990812-4.xhtml",
418 "dom/base/test/chrome/file_bug990812-5.xhtml",
419 "dom/base/test/chrome/file_bug990812.xhtml",
420 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
421 "dom/base/test/chrome/test_bug339494.xhtml",
422 "dom/base/test/chrome/test_bug429785.xhtml",
423 "dom/base/test/chrome/test_bug467123.xhtml",
424 "dom/base/test/chrome/test_bug683852.xhtml",
425 "dom/base/test/chrome/test_bug780529.xhtml",
426 "dom/base/test/chrome/test_bug800386.xhtml",
427 "dom/base/test/chrome/test_bug884693.xhtml",
428 "dom/base/test/chrome/test_document-element-inserted.xhtml",
429 "dom/base/test/chrome/test_domparsing.xhtml",
430 "dom/base/test/chrome/test_fileconstructor.xhtml",
431 "dom/base/test/chrome/title_window.xhtml",
432 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
433 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
434 "dom/base/test/test_domrequesthelper.xhtml",
435 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
436 "dom/console/tests/test_jsm.xhtml",
437 "dom/events/test/test_bug1412775.xhtml",
438 "dom/events/test/test_bug336682_2.xhtml",
439 "dom/events/test/test_bug415498.xhtml",
440 "dom/events/test/test_bug602962.xhtml",
441 "dom/events/test/test_bug617528.xhtml",
442 "dom/events/test/test_bug679494.xhtml",
443 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
444 "dom/indexedDB/test/test_wrappedArray.xhtml",
445 "dom/ipc/test.xhtml",
446 "dom/ipc/tests/test_process_error.xhtml",
447 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
448 "dom/security/test/general/test_bug1277803.xhtml",
449 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
450 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
451 "dom/system/tests/test_constants.xhtml",
452 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
453 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
454 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
455 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
456 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
457 "dom/tests/mochitest/chrome/window_focus.xhtml",
458 "dom/url/tests/test_bug883784.xhtml",
459 "dom/workers/test/test_WorkerDebugger.xhtml",
460 "dom/workers/test/test_WorkerDebugger_console.xhtml",
461 "dom/workers/test/test_fileReadSlice.xhtml",
462 "dom/workers/test/test_fileReaderSync.xhtml",
463 "dom/workers/test/test_fileSlice.xhtml",
466 "mozilla/no-useless-parameters": "off",
467 "mozilla/no-useless-removeEventListener": "off",
468 "mozilla/use-chromeutils-generateqi": "off",
469 "mozilla/use-services": "off",
471 "no-array-constructor": "off",
475 "no-lone-blocks": "off",
476 "no-redeclare": "off",
478 "no-throw-literal": "off",
480 "no-unsanitized/method": "off",
481 "no-unused-vars": "off",
482 "no-useless-return": "off",
483 "object-shorthand": "off",
492 "editor/libeditor/tests/**",
493 "editor/spellchecker/tests/test_bug338427.html",
495 "image/test/browser/browser_image.js",
502 "security/manager/**",
504 "storage/test/unit/test_vacuum.js",
505 "taskcluster/docker/periodic-updates/scripts/**",
508 "widget/tests/test_assign_event_data.html",
511 "mozilla/prefer-boolean-length-check": "off",
515 // TODO: Bug 1609271 Fix all violations for ChromeUtils.import(..., null)
517 "browser/base/content/test/forms/head.js",
518 "browser/base/content/test/general/browser_datachoices_notification.js",
519 "browser/base/content/test/sync/browser_fxa_web_channel.js",
520 "browser/base/content/test/webextensions/head.js",
521 "browser/components/customizableui/test/browser_1042100_default_placements_update.js",
522 "browser/components/customizableui/test/browser_1096763_seen_widgets_post_reset.js",
523 "browser/components/customizableui/test/browser_1161838_inserted_new_default_buttons.js",
524 "browser/components/customizableui/test/browser_989338_saved_placements_not_resaved.js",
525 "browser/components/customizableui/test/browser_currentset_post_reset.js",
526 "browser/components/customizableui/test/browser_panel_keyboard_navigation.js",
527 "browser/components/customizableui/test/browser_proton_toolbar_hide_toolbarbuttons.js",
528 "browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js",
529 "browser/components/enterprisepolicies/tests/xpcshell/head.js",
530 "browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js",
531 "browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js",
532 "browser/components/extensions/test/browser/browser_ext_browserAction_context.js",
533 "browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload.js",
534 "browser/components/extensions/test/browser/browser_ext_currentWindow.js",
535 "browser/components/extensions/test/browser/browser_ext_getViews.js",
536 "browser/components/extensions/test/browser/browser_ext_management.js",
537 "browser/components/extensions/test/browser/browser_ext_pageAction_context.js",
538 "browser/components/extensions/test/browser/browser_ext_pageAction_show_matches.js",
539 "browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_private.js",
540 "browser/components/extensions/test/browser/browser_ext_sessions_restore.js",
541 "browser/components/extensions/test/browser/browser_ext_tabs_audio.js",
542 "browser/components/extensions/test/browser/browser_ext_tabs_duplicate.js",
543 "browser/components/extensions/test/browser/browser_ext_tabs_removeCSS.js",
544 "browser/components/extensions/test/browser/browser_ext_tabs_zoom.js",
545 "browser/components/extensions/test/browser/browser_ext_windows.js",
546 "browser/components/extensions/test/browser/browser_ext_windows_events.js",
547 "browser/components/extensions/test/browser/head.js",
548 "browser/components/extensions/test/xpcshell/test_ext_url_overrides_newtab.js",
549 "browser/components/migration/tests/unit/test_Edge_db_migration.js",
550 "browser/components/translation/test/unit/test_cld2.js",
551 "browser/extensions/formautofill/test/unit/test_sync.js",
552 "browser/extensions/report-site-issue/test/browser/head.js",
553 "devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js",
554 "dom/ipc/tests/browser_memory_distribution_telemetry.js",
555 "dom/push/test/xpcshell/head.js",
556 "dom/push/test/xpcshell/test_broadcast_success.js",
557 "dom/push/test/xpcshell/test_crypto.js",
558 "security/manager/ssl/RemoteSecuritySettings.jsm",
559 "services/common/tests/unit/head_helpers.js",
560 "services/common/tests/unit/test_uptake_telemetry.js",
561 "services/fxaccounts/tests/xpcshell/test_accounts.js",
562 "services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js",
563 "services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js",
564 "services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js",
565 "services/fxaccounts/tests/xpcshell/test_oauth_tokens.js",
566 "services/fxaccounts/tests/xpcshell/test_web_channel.js",
567 "services/sync/modules-testing/utils.js",
568 "services/sync/tests/unit/test_postqueue.js",
569 "toolkit/components/cloudstorage/tests/unit/test_cloudstorage.js",
570 "toolkit/components/crashes/tests/xpcshell/test_crash_manager.js",
571 "toolkit/components/crashes/tests/xpcshell/test_crash_service.js",
572 "toolkit/components/crashes/tests/xpcshell/test_crash_store.js",
573 "toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm",
574 "toolkit/components/extensions/ExtensionPreferencesManager.jsm",
575 "toolkit/components/extensions/ExtensionXPCShellUtils.jsm",
576 "toolkit/components/extensions/parent/ext-management.js",
577 "toolkit/components/extensions/test/mochitest/test_ext_contentscript_cache.html",
578 "toolkit/components/extensions/test/xpcshell/head_native_messaging.js",
579 "toolkit/components/extensions/test/xpcshell/test_ext_api_permissions.js",
580 "toolkit/components/extensions/test/xpcshell/test_ext_background_early_shutdown.js",
581 "toolkit/components/extensions/test/xpcshell/test_ext_background_teardown.js",
582 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_context.js",
583 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_context_isolation.js",
584 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_teardown.js",
585 "toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js",
586 "toolkit/components/extensions/test/xpcshell/test_ext_privacy_disable.js",
587 "toolkit/components/extensions/test/xpcshell/test_ext_schemas_interactive.js",
588 "toolkit/components/extensions/test/xpcshell/test_ext_shutdown_cleanup.js",
589 "toolkit/components/extensions/test/xpcshell/test_ext_storage_sync_kinto.js",
590 "toolkit/components/extensions/test/xpcshell/test_ext_storage_sync_kinto_crypto.js",
591 "toolkit/components/extensions/test/xpcshell/test_ext_tab_teardown.js",
592 "toolkit/components/extensions/test/xpcshell/test_native_manifests.js",
593 "toolkit/components/featuregates/test/unit/test_FeatureGate.js",
594 "toolkit/components/normandy/test/browser/browser_actions_ShowHeartbeatAction.js",
595 "toolkit/components/osfile/modules/osfile_async_front.jsm",
596 "toolkit/components/osfile/modules/osfile_native.jsm",
597 "toolkit/components/osfile/tests/xpcshell/test_osfile_kill.js",
598 "toolkit/components/passwordmgr/test/unit/test_getFormFields.js",
599 "toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js",
600 "toolkit/components/passwordmgr/test/unit/test_getUserNameAndPasswordFields.js",
601 "toolkit/components/processsingleton/MainProcessSingleton.jsm",
602 "toolkit/modules/subprocess/test/xpcshell/test_subprocess.js",
603 "toolkit/modules/tests/xpcshell/test_GMPInstallManager.js",
604 "toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
605 "toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
606 "toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
607 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js",
608 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_regexp_split.js",
609 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js",
610 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_telemetry.js",
611 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklistchange.js",
612 "toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js",
613 "toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js",
614 "toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js",
615 "toolkit/mozapps/extensions/test/xpcshell/test_signed_updatepref.js",
616 "toolkit/mozapps/extensions/test/xpcshell/test_signed_verify.js",
617 "toolkit/mozapps/extensions/test/xpcshell/test_webextension.js",
618 "toolkit/mozapps/extensions/test/xpcshell/test_webextension_events.js",
619 "toolkit/mozapps/extensions/test/xpcshell/test_XPIStates.js",
620 "toolkit/mozapps/installer/precompile_cache.js",
623 "mozilla/reject-chromeutils-import-params": "off",