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 "dom/base/test/chrome/file_bug1139964.xhtml",
343 "dom/base/test/chrome/file_bug549682.xhtml",
344 "dom/base/test/chrome/file_bug616841.xhtml",
345 "dom/base/test/chrome/file_bug990812-1.xhtml",
346 "dom/base/test/chrome/file_bug990812-2.xhtml",
347 "dom/base/test/chrome/file_bug990812-3.xhtml",
348 "dom/base/test/chrome/file_bug990812-4.xhtml",
349 "dom/base/test/chrome/file_bug990812-5.xhtml",
350 "dom/base/test/chrome/file_bug990812.xhtml",
351 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
352 "dom/base/test/chrome/test_bug339494.xhtml",
353 "dom/base/test/chrome/test_bug429785.xhtml",
354 "dom/base/test/chrome/test_bug467123.xhtml",
355 "dom/base/test/chrome/test_bug683852.xhtml",
356 "dom/base/test/chrome/test_bug780529.xhtml",
357 "dom/base/test/chrome/test_bug800386.xhtml",
358 "dom/base/test/chrome/test_bug884693.xhtml",
359 "dom/base/test/chrome/test_document-element-inserted.xhtml",
360 "dom/base/test/chrome/test_domparsing.xhtml",
361 "dom/base/test/chrome/test_fileconstructor.xhtml",
362 "dom/base/test/chrome/title_window.xhtml",
363 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
364 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
365 "dom/base/test/test_domrequesthelper.xhtml",
366 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
367 "dom/console/tests/test_jsm.xhtml",
368 "dom/events/test/test_bug1412775.xhtml",
369 "dom/events/test/test_bug336682_2.xhtml",
370 "dom/events/test/test_bug415498.xhtml",
371 "dom/events/test/test_bug602962.xhtml",
372 "dom/events/test/test_bug617528.xhtml",
373 "dom/events/test/test_bug679494.xhtml",
374 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
375 "dom/indexedDB/test/test_wrappedArray.xhtml",
376 "dom/ipc/test.xhtml",
377 "dom/ipc/tests/test_process_error.xhtml",
378 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
379 "dom/security/test/general/test_bug1277803.xhtml",
380 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
381 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
382 "dom/system/tests/test_constants.xhtml",
383 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
384 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
385 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
386 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
387 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
388 "dom/tests/mochitest/chrome/window_focus.xhtml",
389 "dom/url/tests/test_bug883784.xhtml",
390 "dom/workers/test/test_WorkerDebugger.xhtml",
391 "dom/workers/test/test_WorkerDebugger_console.xhtml",
392 "dom/workers/test/test_fileReadSlice.xhtml",
393 "dom/workers/test/test_fileReaderSync.xhtml",
394 "dom/workers/test/test_fileSlice.xhtml",
397 "mozilla/no-useless-parameters": "off",
398 "mozilla/no-useless-removeEventListener": "off",
399 "mozilla/use-chromeutils-generateqi": "off",
400 "mozilla/use-services": "off",
402 "no-array-constructor": "off",
406 "no-lone-blocks": "off",
408 "no-redeclare": "off",
410 "no-throw-literal": "off",
412 "no-unsanitized/method": "off",
413 "no-unused-vars": "off",
414 "no-useless-return": "off",
415 "object-shorthand": "off",
424 "editor/libeditor/tests/**",
425 "editor/spellchecker/tests/test_bug338427.html",
427 "image/test/browser/browser_image.js",
434 "security/manager/**",
436 "storage/test/unit/test_vacuum.js",
437 "taskcluster/docker/periodic-updates/scripts/**",
440 "widget/tests/test_assign_event_data.html",
443 "mozilla/prefer-boolean-length-check": "off",
447 // TODO: Bug 1609271 Fix all violations for ChromeUtils.import(..., null)
449 "browser/base/content/test/forms/head.js",
450 "browser/base/content/test/general/browser_datachoices_notification.js",
451 "browser/base/content/test/sync/browser_fxa_web_channel.js",
452 "browser/base/content/test/webextensions/head.js",
453 "browser/components/customizableui/test/browser_1042100_default_placements_update.js",
454 "browser/components/customizableui/test/browser_1096763_seen_widgets_post_reset.js",
455 "browser/components/customizableui/test/browser_1161838_inserted_new_default_buttons.js",
456 "browser/components/customizableui/test/browser_989338_saved_placements_not_resaved.js",
457 "browser/components/customizableui/test/browser_currentset_post_reset.js",
458 "browser/components/customizableui/test/browser_panel_keyboard_navigation.js",
459 "browser/components/customizableui/test/browser_proton_toolbar_hide_toolbarbuttons.js",
460 "browser/components/enterprisepolicies/tests/browser/browser_policies_setAndLockPref_API.js",
461 "browser/components/enterprisepolicies/tests/xpcshell/head.js",
462 "browser/components/enterprisepolicies/tests/xpcshell/test_proxy.js",
463 "browser/components/enterprisepolicies/tests/xpcshell/test_runOnce_helper.js",
464 "browser/components/extensions/test/browser/browser_ext_browserAction_context.js",
465 "browser/components/extensions/test/browser/browser_ext_browserAction_popup_preload.js",
466 "browser/components/extensions/test/browser/browser_ext_currentWindow.js",
467 "browser/components/extensions/test/browser/browser_ext_getViews.js",
468 "browser/components/extensions/test/browser/browser_ext_management.js",
469 "browser/components/extensions/test/browser/browser_ext_pageAction_context.js",
470 "browser/components/extensions/test/browser/browser_ext_pageAction_show_matches.js",
471 "browser/components/extensions/test/browser/browser_ext_sessions_getRecentlyClosed_private.js",
472 "browser/components/extensions/test/browser/browser_ext_sessions_restore.js",
473 "browser/components/extensions/test/browser/browser_ext_tabs_audio.js",
474 "browser/components/extensions/test/browser/browser_ext_tabs_duplicate.js",
475 "browser/components/extensions/test/browser/browser_ext_tabs_removeCSS.js",
476 "browser/components/extensions/test/browser/browser_ext_tabs_zoom.js",
477 "browser/components/extensions/test/browser/browser_ext_windows.js",
478 "browser/components/extensions/test/browser/browser_ext_windows_events.js",
479 "browser/components/extensions/test/browser/head.js",
480 "browser/components/extensions/test/xpcshell/test_ext_url_overrides_newtab.js",
481 "browser/components/migration/tests/unit/test_Edge_db_migration.js",
482 "browser/components/translation/test/unit/test_cld2.js",
483 "browser/extensions/formautofill/test/unit/test_sync.js",
484 "browser/extensions/report-site-issue/test/browser/head.js",
485 "devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js",
486 "dom/ipc/tests/browser_memory_distribution_telemetry.js",
487 "dom/push/test/xpcshell/head.js",
488 "dom/push/test/xpcshell/test_broadcast_success.js",
489 "dom/push/test/xpcshell/test_crypto.js",
490 "security/manager/ssl/RemoteSecuritySettings.jsm",
491 "services/common/tests/unit/head_helpers.js",
492 "services/common/tests/unit/test_uptake_telemetry.js",
493 "services/fxaccounts/tests/xpcshell/test_accounts.js",
494 "services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js",
495 "services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js",
496 "services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js",
497 "services/fxaccounts/tests/xpcshell/test_oauth_tokens.js",
498 "services/fxaccounts/tests/xpcshell/test_web_channel.js",
499 "services/sync/modules-testing/utils.js",
500 "services/sync/tests/unit/test_postqueue.js",
501 "toolkit/components/cloudstorage/tests/unit/test_cloudstorage.js",
502 "toolkit/components/crashes/tests/xpcshell/test_crash_manager.js",
503 "toolkit/components/crashes/tests/xpcshell/test_crash_service.js",
504 "toolkit/components/crashes/tests/xpcshell/test_crash_store.js",
505 "toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm",
506 "toolkit/components/extensions/ExtensionPreferencesManager.jsm",
507 "toolkit/components/extensions/ExtensionXPCShellUtils.jsm",
508 "toolkit/components/extensions/parent/ext-management.js",
509 "toolkit/components/extensions/test/mochitest/test_ext_contentscript_cache.html",
510 "toolkit/components/extensions/test/xpcshell/head_native_messaging.js",
511 "toolkit/components/extensions/test/xpcshell/test_ext_api_permissions.js",
512 "toolkit/components/extensions/test/xpcshell/test_ext_background_early_shutdown.js",
513 "toolkit/components/extensions/test/xpcshell/test_ext_background_teardown.js",
514 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_context.js",
515 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_context_isolation.js",
516 "toolkit/components/extensions/test/xpcshell/test_ext_contentscript_teardown.js",
517 "toolkit/components/extensions/test/xpcshell/test_ext_contexts_gc.js",
518 "toolkit/components/extensions/test/xpcshell/test_ext_privacy_disable.js",
519 "toolkit/components/extensions/test/xpcshell/test_ext_schemas_interactive.js",
520 "toolkit/components/extensions/test/xpcshell/test_ext_shutdown_cleanup.js",
521 "toolkit/components/extensions/test/xpcshell/test_ext_storage_sync_kinto.js",
522 "toolkit/components/extensions/test/xpcshell/test_ext_storage_sync_kinto_crypto.js",
523 "toolkit/components/extensions/test/xpcshell/test_ext_tab_teardown.js",
524 "toolkit/components/extensions/test/xpcshell/test_native_manifests.js",
525 "toolkit/components/featuregates/test/unit/test_FeatureGate.js",
526 "toolkit/components/normandy/test/browser/browser_actions_ShowHeartbeatAction.js",
527 "toolkit/components/osfile/modules/osfile_async_front.jsm",
528 "toolkit/components/osfile/modules/osfile_native.jsm",
529 "toolkit/components/osfile/tests/xpcshell/test_osfile_kill.js",
530 "toolkit/components/passwordmgr/test/unit/test_getFormFields.js",
531 "toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js",
532 "toolkit/components/passwordmgr/test/unit/test_getUserNameAndPasswordFields.js",
533 "toolkit/components/processsingleton/MainProcessSingleton.jsm",
534 "toolkit/modules/subprocess/test/xpcshell/test_subprocess.js",
535 "toolkit/modules/tests/xpcshell/test_GMPInstallManager.js",
536 "toolkit/mozapps/extensions/internal/AddonTestUtils.jsm",
537 "toolkit/mozapps/extensions/test/browser/browser_gmpProvider.js",
538 "toolkit/mozapps/extensions/test/xpcshell/head_addons.js",
539 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_clients.js",
540 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_regexp_split.js",
541 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_targetapp_filter.js",
542 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklist_telemetry.js",
543 "toolkit/mozapps/extensions/test/xpcshell/rs-blocklist/test_blocklistchange.js",
544 "toolkit/mozapps/extensions/test/xpcshell/test_gmpProvider.js",
545 "toolkit/mozapps/extensions/test/xpcshell/test_no_addons.js",
546 "toolkit/mozapps/extensions/test/xpcshell/test_permissions_prefs.js",
547 "toolkit/mozapps/extensions/test/xpcshell/test_signed_updatepref.js",
548 "toolkit/mozapps/extensions/test/xpcshell/test_signed_verify.js",
549 "toolkit/mozapps/extensions/test/xpcshell/test_webextension.js",
550 "toolkit/mozapps/extensions/test/xpcshell/test_webextension_events.js",
551 "toolkit/mozapps/extensions/test/xpcshell/test_XPIStates.js",
552 "toolkit/mozapps/installer/precompile_cache.js",
555 "mozilla/reject-chromeutils-import-params": "off",