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 ...browserTestConfig,
129 files: browserTestPaths.map(path => `${path}**`),
132 ...removeOverrides(mochitestTestConfig),
133 files: mochitestTestPaths.map(path => `${path}**`),
134 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
137 ...removeOverrides(chromeTestConfig),
138 files: chromeTestPaths.map(path => `${path}**`),
142 // Ideally we wouldn't be using the simpletest env here, but our uses of
143 // js files mean we pick up everything from the global scope, which could
144 // be any one of a number of html files. So we just allow the basics...
145 "mozilla/simpletest": true,
148 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
149 ...chromeTestPaths.map(path => `${path}/**/*.js`),
154 "netwerk/cookie/test/browser/**",
155 "netwerk/test/browser/**",
156 "netwerk/test/mochitests/**",
157 "netwerk/test/unit*/**",
160 "mozilla/no-arbitrary-setTimeout": "off",
161 "mozilla/no-define-cc-etc": "off",
162 "mozilla/use-services": "off",
163 "consistent-return": "off",
165 "no-global-assign": "off",
166 "no-nested-ternary": "off",
167 "no-redeclare": "off",
169 "no-throw-literal": "off",
173 files: ["layout/**"],
175 "object-shorthand": "off",
176 "mozilla/avoid-removeChild": "off",
177 "mozilla/consistent-if-bracing": "off",
178 "mozilla/reject-importGlobalProperties": "off",
179 "mozilla/no-arbitrary-setTimeout": "off",
180 "mozilla/no-define-cc-etc": "off",
181 "mozilla/use-chromeutils-generateqi": "off",
182 "mozilla/use-default-preference-values": "off",
183 "mozilla/use-includes-instead-of-indexOf": "off",
184 "mozilla/use-services": "off",
185 "mozilla/use-ownerGlobal": "off",
187 "consistent-return": "off",
188 "no-array-constructor": "off",
190 "no-cond-assign": "off",
191 "no-extra-boolean-cast": "off",
193 "no-func-assign": "off",
194 "no-global-assign": "off",
195 "no-implied-eval": "off",
196 "no-lonely-if": "off",
197 "no-nested-ternary": "off",
198 "no-new-wrappers": "off",
199 "no-redeclare": "off",
200 "no-restricted-globals": "off",
201 "no-return-await": "off",
202 "no-sequences": "off",
203 "no-throw-literal": "off",
204 "no-useless-concat": "off",
206 "no-unreachable": "off",
207 "no-unsanitized/method": "off",
208 "no-unsanitized/property": "off",
209 "no-unsafe-negation": "off",
210 "no-unused-vars": "off",
211 "no-useless-return": "off",
218 "dom/base/test/unit/test_serializers_entities*.js",
219 "dom/base/test/unit_ipc/**",
220 "dom/base/test/jsmodules/**",
229 "dom/media/tests/**",
230 "dom/media/webaudio/**",
231 "dom/media/webrtc/tests/**",
232 "dom/media/webspeech/**",
233 "dom/messagechannel/**",
237 "dom/performance/**",
240 "dom/security/test/cors/**",
241 "dom/security/test/csp/**",
242 "dom/security/test/mixedcontentblocker/**",
243 "dom/serviceworkers/**",
245 "dom/tests/mochitest/**",
256 "dom/ipc/test.xhtml",
259 "consistent-return": "off",
260 "mozilla/avoid-removeChild": "off",
261 "mozilla/consistent-if-bracing": "off",
262 "mozilla/no-arbitrary-setTimeout": "off",
263 "mozilla/no-compare-against-boolean-literals": "off",
264 "mozilla/no-define-cc-etc": "off",
265 "mozilla/reject-importGlobalProperties": "off",
266 "mozilla/use-cc-etc": "off",
267 "mozilla/use-chromeutils-generateqi": "off",
268 "mozilla/use-chromeutils-import": "off",
269 "mozilla/use-includes-instead-of-indexOf": "off",
270 "mozilla/use-ownerGlobal": "off",
271 "mozilla/use-services": "off",
272 "no-array-constructor": "off",
274 "no-cond-assign": "off",
275 "no-control-regex": "off",
276 "no-debugger": "off",
277 "no-else-return": "off",
280 "no-func-assign": "off",
281 "no-global-assign": "off",
282 "no-implied-eval": "off",
283 "no-lone-blocks": "off",
284 "no-lonely-if": "off",
285 "no-nested-ternary": "off",
286 "no-new-object": "off",
287 "no-new-wrappers": "off",
289 "no-redeclare": "off",
290 "no-return-await": "off",
291 "no-restricted-globals": "off",
292 "no-self-assign": "off",
293 "no-self-compare": "off",
294 "no-sequences": "off",
296 "no-shadow-restricted-names": "off",
297 "no-sparse-arrays": "off",
298 "no-throw-literal": "off",
299 "no-unreachable": "off",
300 "no-unsanitized/method": "off",
301 "no-unsanitized/property": "off",
303 "no-unused-vars": "off",
304 "no-useless-call": "off",
305 "no-useless-concat": "off",
306 "no-useless-return": "off",
312 "testing/mochitest/browser-harness.xhtml",
313 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
314 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
315 "testing/mochitest/chrome/test_sanityException.xhtml",
316 "testing/mochitest/chrome/test_sanityException2.xhtml",
317 "testing/mochitest/harness.xhtml",
320 "dot-notation": "off",
321 "object-shorthand": "off",
322 "mozilla/use-services": "off",
323 "mozilla/no-compare-against-boolean-literals": "off",
324 "mozilla/no-useless-parameters": "off",
325 "mozilla/no-useless-removeEventListener": "off",
326 "mozilla/use-cc-etc": "off",
327 "consistent-return": "off",
328 "no-fallthrough": "off",
329 "no-nested-ternary": "off",
330 "no-redeclare": "off",
331 "no-sequences": "off",
333 "no-throw-literal": "off",
335 "no-unsanitized/property": "off",
336 "no-unused-vars": "off",
337 "no-useless-call": "off",
342 "docshell/test/chrome/bug113934_window.xhtml",
343 "docshell/test/chrome/bug215405_window.xhtml",
344 "docshell/test/chrome/bug293235_window.xhtml",
345 "docshell/test/chrome/bug294258_window.xhtml",
346 "docshell/test/chrome/bug298622_window.xhtml",
347 "docshell/test/chrome/bug301397_window.xhtml",
348 "docshell/test/chrome/bug303267_window.xhtml",
349 "docshell/test/chrome/bug311007_window.xhtml",
350 "docshell/test/chrome/bug321671_window.xhtml",
351 "docshell/test/chrome/bug360511_window.xhtml",
352 "docshell/test/chrome/bug396519_window.xhtml",
353 "docshell/test/chrome/bug396649_window.xhtml",
354 "docshell/test/chrome/bug449778_window.xhtml",
355 "docshell/test/chrome/bug449780_window.xhtml",
356 "docshell/test/chrome/bug582176_window.xhtml",
357 "docshell/test/chrome/bug662200_window.xhtml",
358 "docshell/test/chrome/bug690056_window.xhtml",
359 "docshell/test/chrome/bug89419_window.xhtml",
360 "docshell/test/chrome/mozFrameType_window.xhtml",
361 "docshell/test/chrome/test_bug453650.xhtml",
362 "docshell/test/chrome/test_bug454235.xhtml",
363 "docshell/test/chrome/test_bug565388.xhtml",
364 "docshell/test/chrome/test_bug608669.xhtml",
365 "docshell/test/chrome/test_bug789773.xhtml",
366 "docshell/test/chrome/test_bug846906.xhtml",
367 "docshell/test/chrome/test_docRedirect.xhtml",
368 "docshell/test/chrome/test_principalInherit.xhtml",
369 "docshell/test/chrome/test_viewsource_forbidden_in_iframe.xhtml",
372 "no-global-assign": "off",
374 "mozilla/no-useless-removeEventListener": "off",
375 "mozilla/use-services": "off",
376 "mozilla/use-chromeutils-generateqi": "off",
377 "no-delete-var": "off",
378 "no-redeclare": "off",
383 "dom/base/test/chrome/file_bug1139964.xhtml",
384 "dom/base/test/chrome/file_bug549682.xhtml",
385 "dom/base/test/chrome/file_bug616841.xhtml",
386 "dom/base/test/chrome/file_bug990812-1.xhtml",
387 "dom/base/test/chrome/file_bug990812-2.xhtml",
388 "dom/base/test/chrome/file_bug990812-3.xhtml",
389 "dom/base/test/chrome/file_bug990812-4.xhtml",
390 "dom/base/test/chrome/file_bug990812-5.xhtml",
391 "dom/base/test/chrome/file_bug990812.xhtml",
392 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
393 "dom/base/test/chrome/test_bug339494.xhtml",
394 "dom/base/test/chrome/test_bug429785.xhtml",
395 "dom/base/test/chrome/test_bug467123.xhtml",
396 "dom/base/test/chrome/test_bug683852.xhtml",
397 "dom/base/test/chrome/test_bug780529.xhtml",
398 "dom/base/test/chrome/test_bug800386.xhtml",
399 "dom/base/test/chrome/test_bug884693.xhtml",
400 "dom/base/test/chrome/test_document-element-inserted.xhtml",
401 "dom/base/test/chrome/test_domparsing.xhtml",
402 "dom/base/test/chrome/test_fileconstructor.xhtml",
403 "dom/base/test/chrome/title_window.xhtml",
404 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
405 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
406 "dom/base/test/test_domrequesthelper.xhtml",
407 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
408 "dom/console/tests/test_jsm.xhtml",
409 "dom/events/test/test_bug1412775.xhtml",
410 "dom/events/test/test_bug336682_2.xhtml",
411 "dom/events/test/test_bug415498.xhtml",
412 "dom/events/test/test_bug602962.xhtml",
413 "dom/events/test/test_bug617528.xhtml",
414 "dom/events/test/test_bug679494.xhtml",
415 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
416 "dom/indexedDB/test/test_wrappedArray.xhtml",
417 "dom/ipc/test.xhtml",
418 "dom/ipc/tests/test_process_error.xhtml",
419 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
420 "dom/security/test/general/test_bug1277803.xhtml",
421 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
422 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
423 "dom/system/tests/test_constants.xhtml",
424 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
425 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
426 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
427 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
428 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
429 "dom/tests/mochitest/chrome/window_focus.xhtml",
430 "dom/url/tests/test_bug883784.xhtml",
431 "dom/workers/test/test_WorkerDebugger.xhtml",
432 "dom/workers/test/test_WorkerDebugger_console.xhtml",
433 "dom/workers/test/test_fileReadSlice.xhtml",
434 "dom/workers/test/test_fileReaderSync.xhtml",
435 "dom/workers/test/test_fileSlice.xhtml",
438 "mozilla/no-useless-parameters": "off",
439 "mozilla/no-useless-removeEventListener": "off",
440 "mozilla/use-chromeutils-generateqi": "off",
441 "mozilla/use-services": "off",
443 "no-array-constructor": "off",
447 "no-lone-blocks": "off",
449 "no-redeclare": "off",
451 "no-throw-literal": "off",
453 "no-unsanitized/method": "off",
454 "no-unused-vars": "off",
455 "no-useless-return": "off",
456 "object-shorthand": "off",
465 "editor/libeditor/tests/**",
466 "editor/spellchecker/tests/test_bug338427.html",
468 "image/test/browser/browser_image.js",
475 "security/manager/**",
477 "storage/test/unit/test_vacuum.js",
478 "taskcluster/docker/periodic-updates/scripts/**",
481 "widget/tests/test_assign_event_data.html",
484 "mozilla/prefer-boolean-length-check": "off",
488 // TODO: Bug 1609271 Fix all violations for ChromeUtils.import(..., null)
490 "browser/base/content/test/forms/head.js",
491 "browser/base/content/test/general/browser_datachoices_notification.js",
492 "browser/base/content/test/sync/browser_fxa_web_channel.js",
493 "browser/base/content/test/webextensions/head.js",
494 "browser/components/customizableui/test/browser_1042100_default_placements_update.js",
495 "browser/components/customizableui/test/browser_1096763_seen_widgets_post_reset.js",
496 "browser/components/customizableui/test/browser_1161838_inserted_new_default_buttons.js",
497 "browser/components/customizableui/test/browser_989338_saved_placements_not_resaved.js",
498 "browser/components/customizableui/test/browser_currentset_post_reset.js",
499 "browser/components/customizableui/test/browser_panel_keyboard_navigation.js",
500 "browser/components/customizableui/test/browser_proton_toolbar_hide_toolbarbuttons.js",
501 "browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js",
502 "browser/components/enterprisepolicies/tests/xpcshell/head.js",
503 "browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js",
504 "browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js",
505 "browser/components/extensions/test/browser/browser_ext_browserAction_context.js",
506 "browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload.js",
507 "browser/components/extensions/test/browser/browser_ext_currentWindow.js",
508 "browser/components/extensions/test/browser/browser_ext_getViews.js",
509 "browser/components/extensions/test/browser/browser_ext_management.js",
510 "browser/components/extensions/test/browser/browser_ext_pageAction_context.js",
511 "browser/components/extensions/test/browser/browser_ext_pageAction_show_matches.js",
512 "browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_private.js",
513 "browser/components/extensions/test/browser/browser_ext_sessions_restore.js",
514 "browser/components/extensions/test/browser/browser_ext_tabs_audio.js",
515 "browser/components/extensions/test/browser/browser_ext_tabs_duplicate.js",
516 "browser/components/extensions/test/browser/browser_ext_tabs_removeCSS.js",
517 "browser/components/extensions/test/browser/browser_ext_tabs_zoom.js",
518 "browser/components/extensions/test/browser/browser_ext_windows.js",
519 "browser/components/extensions/test/browser/browser_ext_windows_events.js",
520 "browser/components/extensions/test/browser/head.js",
521 "browser/components/extensions/test/xpcshell/test_ext_url_overrides_newtab.js",
522 "browser/components/migration/tests/unit/test_Edge_db_migration.js",
523 "browser/components/translation/test/unit/test_cld2.js",
524 "browser/extensions/formautofill/test/unit/test_sync.js",
525 "browser/extensions/report-site-issue/test/browser/head.js",
526 "devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js",
527 "dom/ipc/tests/browser_memory_distribution_telemetry.js",
528 "dom/push/test/xpcshell/head.js",
529 "dom/push/test/xpcshell/test_broadcast_success.js",
530 "dom/push/test/xpcshell/test_crypto.js",
531 "security/manager/ssl/RemoteSecuritySettings.jsm",
532 "services/common/tests/unit/head_helpers.js",
533 "services/common/tests/unit/test_uptake_telemetry.js",
534 "services/fxaccounts/tests/xpcshell/test_accounts.js",
535 "services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js",
536 "services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js",
537 "services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js",
538 "services/fxaccounts/tests/xpcshell/test_oauth_tokens.js",
539 "services/fxaccounts/tests/xpcshell/test_web_channel.js",
540 "services/sync/modules-testing/utils.js",
541 "services/sync/tests/unit/test_postqueue.js",
542 "toolkit/components/cloudstorage/tests/unit/test_cloudstorage.js",
543 "toolkit/components/crashes/tests/xpcshell/test_crash_manager.js",
544 "toolkit/components/crashes/tests/xpcshell/test_crash_service.js",
545 "toolkit/components/crashes/tests/xpcshell/test_crash_store.js",
546 "toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm",
547 "toolkit/components/extensions/ExtensionPreferencesManager.jsm",
548 "toolkit/components/extensions/ExtensionXPCShellUtils.jsm",
549 "toolkit/components/extensions/parent/ext-management.js",
550 "toolkit/components/extensions/test/mochitest/test_ext_contentscript_cache.html",
551 "toolkit/components/extensions/test/xpcshell/head_native_messaging.js",
552 "toolkit/components/extensions/test/xpcshell/test_ext_api_permissions.js",
553 "toolkit/components/extensions/test/xpcshell/test_ext_background_early_shutdown.js",
554 "toolkit/components/extensions/test/xpcshell/test_ext_background_teardown.js",
555 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_context.js",
556 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_context_isolation.js",
557 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_teardown.js",
558 "toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js",
559 "toolkit/components/extensions/test/xpcshell/test_ext_privacy_disable.js",
560 "toolkit/components/extensions/test/xpcshell/test_ext_schemas_interactive.js",
561 "toolkit/components/extensions/test/xpcshell/test_ext_shutdown_cleanup.js",
562 "toolkit/components/extensions/test/xpcshell/test_ext_storage_sync_kinto.js",
563 "toolkit/components/extensions/test/xpcshell/test_ext_storage_sync_kinto_crypto.js",
564 "toolkit/components/extensions/test/xpcshell/test_ext_tab_teardown.js",
565 "toolkit/components/extensions/test/xpcshell/test_native_manifests.js",
566 "toolkit/components/featuregates/test/unit/test_FeatureGate.js",
567 "toolkit/components/normandy/test/browser/browser_actions_ShowHeartbeatAction.js",
568 "toolkit/components/osfile/modules/osfile_async_front.jsm",
569 "toolkit/components/osfile/modules/osfile_native.jsm",
570 "toolkit/components/osfile/tests/xpcshell/test_osfile_kill.js",
571 "toolkit/components/passwordmgr/test/unit/test_getFormFields.js",
572 "toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js",
573 "toolkit/components/passwordmgr/test/unit/test_getUserNameAndPasswordFields.js",
574 "toolkit/components/processsingleton/MainProcessSingleton.jsm",
575 "toolkit/modules/subprocess/test/xpcshell/test_subprocess.js",
576 "toolkit/modules/tests/xpcshell/test_GMPInstallManager.js",
577 "toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
578 "toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
579 "toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
580 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js",
581 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_regexp_split.js",
582 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js",
583 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_telemetry.js",
584 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklistchange.js",
585 "toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js",
586 "toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js",
587 "toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js",
588 "toolkit/mozapps/extensions/test/xpcshell/test_signed_updatepref.js",
589 "toolkit/mozapps/extensions/test/xpcshell/test_signed_verify.js",
590 "toolkit/mozapps/extensions/test/xpcshell/test_webextension.js",
591 "toolkit/mozapps/extensions/test/xpcshell/test_webextension_events.js",
592 "toolkit/mozapps/extensions/test/xpcshell/test_XPIStates.js",
593 "toolkit/mozapps/installer/precompile_cache.js",
596 "mozilla/reject-chromeutils-import-params": "off",