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")
53 path.join(__dirname, "devtools", "client", "debugger", ".eslintignore")
57 .filter(p => p && !p.startsWith("#"))
58 .map(p => `devtools/client/debugger/${p}`),
62 parser: "@babel/eslint-parser",
66 configFile: path.join(__dirname, ".babel-eslint.rc.js"),
70 // Ignore eslint configurations in parent directories.
72 // New rules and configurations should generally be added in
73 // tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js to
74 // allow external repositories that use the plugin to pick them up as well.
75 extends: ["plugin:mozilla/recommended"],
79 // All .eslintrc.js files are in the node environment, so turn that
81 // https://github.com/eslint/eslint/issues/13008
82 files: [".eslintrc.js"],
95 "no-redeclare": "warn",
96 "no-unused-vars": "warn",
97 "no-fallthrough": "warn",
98 "no-control-regex": "warn",
99 "no-throw-literal": "warn",
100 "no-useless-concat": "warn",
101 "consistent-return": "warn",
102 "mozilla/use-cc-etc": "warn",
103 "mozilla/use-services": "warn",
104 "mozilla/use-includes-instead-of-indexOf": "warn",
105 "mozilla/no-compare-against-boolean-literals": "warn",
114 "js/src/builtin/**/*.js",
115 "js/src/shell/**/*.js",
118 // Curly brackets are required for all the tree via recommended.js,
119 // however these files aren't auto-fixable at the moment.
124 // TODO: Bug 1515949. Enable no-undef for gfx/
125 files: "gfx/layers/apz/test/mochitest/**",
131 ...removeOverrides(xpcshellTestConfig),
132 files: xpcshellTestPaths.map(path => `${path}**`),
133 excludedFiles: "devtools/**",
136 // If it is an xpcshell head file, we turn off global unused variable checks, as it
137 // would require searching the other test files to know if they are used or not.
138 // This would be expensive and slow, and it isn't worth it for head files.
139 // We could get developers to declare as exported, but that doesn't seem worth it.
140 files: xpcshellTestPaths.map(path => `${path}head*.js`),
152 // This section enables warning of no-unused-vars globally for all test*.js
153 // files in xpcshell test paths.
154 // These are turned into errors with selected exclusions in the next
156 // Bug 1612907: This section should go away once the exclusions are removed
157 // from the following section.
158 files: xpcshellTestPaths.map(path => `${path}test*.js`),
160 // No declaring variables that are never used
171 // This section makes global issues with no-unused-vars be reported as
172 // errors - except for the excluded lists which are being fixed in the
173 // dependencies of bug 1612907.
174 files: xpcshellTestPaths.map(path => `${path}test*.js`),
176 // These are suitable as good first bugs, take one or two related lines
178 "caps/tests/unit/test_origin.js",
179 "caps/tests/unit/test_site_origin.js",
180 "chrome/test/unit/test_no_remote_registration.js",
181 "extensions/permissions/**",
182 "image/test/unit/**",
183 "intl/uconv/tests/unit/test_bug317216.js",
184 "intl/uconv/tests/unit/test_bug340714.js",
185 "modules/libjar/test/unit/test_empty_jar_telemetry.js",
186 "modules/libjar/zipwriter/test/unit/test_alignment.js",
187 "modules/libjar/zipwriter/test/unit/test_bug419769_2.js",
188 "modules/libjar/zipwriter/test/unit/test_storedata.js",
189 "modules/libjar/zipwriter/test/unit/test_zippermissions.js",
190 "modules/libpref/test/unit/test_changeType.js",
191 "modules/libpref/test/unit/test_dirtyPrefs.js",
192 "toolkit/crashreporter/test/unit/test_crash_AsyncShutdown.js",
193 "toolkit/mozapps/update/tests/unit_aus_update/testConstants.js",
194 "xpcom/tests/unit/test_hidden_files.js",
195 "xpcom/tests/unit/test_localfile.js",
197 // These are more complicated bugs which may require some in-depth
198 // investigation or different solutions. They are also likely to be
199 // a reasonable size.
200 "browser/components/**",
201 "browser/modules/**",
204 "security/manager/ssl/tests/unit/**",
206 "testing/xpcshell/**",
207 "toolkit/components/**",
208 "toolkit/modules/**",
211 // No declaring variables that are never used
222 ...browserTestConfig,
223 files: browserTestPaths.map(path => `${path}**`),
226 ...removeOverrides(mochitestTestConfig),
227 files: mochitestTestPaths.map(path => `${path}**`),
228 excludedFiles: ["security/manager/ssl/tests/mochitest/browser/**"],
231 ...removeOverrides(chromeTestConfig),
232 files: chromeTestPaths.map(path => `${path}**`),
236 // Ideally we wouldn't be using the simpletest env here, but our uses of
237 // js files mean we pick up everything from the global scope, which could
238 // be any one of a number of html files. So we just allow the basics...
239 "mozilla/simpletest": true,
242 ...mochitestTestPaths.map(path => `${path}/**/*.js`),
243 ...chromeTestPaths.map(path => `${path}/**/*.js`),
248 "netwerk/cookie/test/browser/**",
249 "netwerk/test/browser/**",
250 "netwerk/test/mochitests/**",
251 "netwerk/test/unit*/**",
254 "mozilla/no-arbitrary-setTimeout": "off",
255 "mozilla/no-define-cc-etc": "off",
256 "consistent-return": "off",
258 "no-global-assign": "off",
259 "no-nested-ternary": "off",
260 "no-redeclare": "off",
262 "no-throw-literal": "off",
266 files: ["layout/**"],
268 "object-shorthand": "off",
269 "mozilla/avoid-removeChild": "off",
270 "mozilla/consistent-if-bracing": "off",
271 "mozilla/reject-importGlobalProperties": "off",
272 "mozilla/no-arbitrary-setTimeout": "off",
273 "mozilla/no-define-cc-etc": "off",
274 "mozilla/use-chromeutils-generateqi": "off",
275 "mozilla/use-default-preference-values": "off",
276 "mozilla/use-includes-instead-of-indexOf": "off",
277 "mozilla/use-services": "off",
278 "mozilla/use-ownerGlobal": "off",
280 "consistent-return": "off",
281 "no-array-constructor": "off",
283 "no-cond-assign": "off",
284 "no-extra-boolean-cast": "off",
286 "no-func-assign": "off",
287 "no-global-assign": "off",
288 "no-implied-eval": "off",
289 "no-lonely-if": "off",
290 "no-nested-ternary": "off",
291 "no-new-wrappers": "off",
292 "no-redeclare": "off",
293 "no-restricted-globals": "off",
294 "no-return-await": "off",
295 "no-sequences": "off",
296 "no-throw-literal": "off",
297 "no-useless-concat": "off",
299 "no-unreachable": "off",
300 "no-unsanitized/method": "off",
301 "no-unsanitized/property": "off",
302 "no-unsafe-negation": "off",
303 "no-unused-vars": "off",
304 "no-useless-return": "off",
311 "dom/base/test/unit/test_serializers_entities*.js",
312 "dom/base/test/unit_ipc/**",
313 "dom/base/test/jsmodules/**",
322 "dom/media/tests/**",
323 "dom/media/webaudio/**",
324 "dom/media/webrtc/tests/**",
325 "dom/media/webspeech/**",
326 "dom/messagechannel/**",
330 "dom/performance/**",
333 "dom/security/test/cors/**",
334 "dom/security/test/csp/**",
335 "dom/security/test/mixedcontentblocker/**",
336 "dom/serviceworkers/**",
338 "dom/tests/mochitest/**",
349 "dom/ipc/test.xhtml",
352 "consistent-return": "off",
353 "mozilla/avoid-removeChild": "off",
354 "mozilla/consistent-if-bracing": "off",
355 "mozilla/no-arbitrary-setTimeout": "off",
356 "mozilla/no-compare-against-boolean-literals": "off",
357 "mozilla/no-define-cc-etc": "off",
358 "mozilla/reject-importGlobalProperties": "off",
359 "mozilla/use-cc-etc": "off",
360 "mozilla/use-chromeutils-generateqi": "off",
361 "mozilla/use-chromeutils-import": "off",
362 "mozilla/use-includes-instead-of-indexOf": "off",
363 "mozilla/use-ownerGlobal": "off",
364 "mozilla/use-services": "off",
365 "no-array-constructor": "off",
367 "no-cond-assign": "off",
368 "no-control-regex": "off",
369 "no-debugger": "off",
370 "no-else-return": "off",
373 "no-func-assign": "off",
374 "no-global-assign": "off",
375 "no-implied-eval": "off",
376 "no-lone-blocks": "off",
377 "no-lonely-if": "off",
378 "no-nested-ternary": "off",
379 "no-new-object": "off",
380 "no-new-wrappers": "off",
381 "no-redeclare": "off",
382 "no-return-await": "off",
383 "no-restricted-globals": "off",
384 "no-self-assign": "off",
385 "no-self-compare": "off",
386 "no-sequences": "off",
388 "no-shadow-restricted-names": "off",
389 "no-sparse-arrays": "off",
390 "no-throw-literal": "off",
391 "no-unreachable": "off",
392 "no-unsanitized/method": "off",
393 "no-unsanitized/property": "off",
395 "no-unused-vars": "off",
396 "no-useless-call": "off",
397 "no-useless-concat": "off",
398 "no-useless-return": "off",
404 "testing/mochitest/browser-harness.xhtml",
405 "testing/mochitest/chrome/test_chromeGetTestFile.xhtml",
406 "testing/mochitest/chrome/test_sanityEventUtils.xhtml",
407 "testing/mochitest/chrome/test_sanityException.xhtml",
408 "testing/mochitest/chrome/test_sanityException2.xhtml",
409 "testing/mochitest/harness.xhtml",
412 "dot-notation": "off",
413 "object-shorthand": "off",
414 "mozilla/use-services": "off",
415 "mozilla/no-compare-against-boolean-literals": "off",
416 "mozilla/no-useless-parameters": "off",
417 "mozilla/no-useless-removeEventListener": "off",
418 "mozilla/use-cc-etc": "off",
419 "consistent-return": "off",
420 "no-fallthrough": "off",
421 "no-nested-ternary": "off",
422 "no-redeclare": "off",
423 "no-sequences": "off",
425 "no-throw-literal": "off",
427 "no-unsanitized/property": "off",
428 "no-unused-vars": "off",
429 "no-useless-call": "off",
434 "dom/base/test/chrome/file_bug1139964.xhtml",
435 "dom/base/test/chrome/file_bug549682.xhtml",
436 "dom/base/test/chrome/file_bug616841.xhtml",
437 "dom/base/test/chrome/file_bug990812-1.xhtml",
438 "dom/base/test/chrome/file_bug990812-2.xhtml",
439 "dom/base/test/chrome/file_bug990812-3.xhtml",
440 "dom/base/test/chrome/file_bug990812-4.xhtml",
441 "dom/base/test/chrome/file_bug990812-5.xhtml",
442 "dom/base/test/chrome/file_bug990812.xhtml",
443 "dom/base/test/chrome/test_bug1098074_throw_from_ReceiveMessage.xhtml",
444 "dom/base/test/chrome/test_bug339494.xhtml",
445 "dom/base/test/chrome/test_bug429785.xhtml",
446 "dom/base/test/chrome/test_bug467123.xhtml",
447 "dom/base/test/chrome/test_bug683852.xhtml",
448 "dom/base/test/chrome/test_bug780529.xhtml",
449 "dom/base/test/chrome/test_bug800386.xhtml",
450 "dom/base/test/chrome/test_bug884693.xhtml",
451 "dom/base/test/chrome/test_document-element-inserted.xhtml",
452 "dom/base/test/chrome/test_domparsing.xhtml",
453 "dom/base/test/chrome/title_window.xhtml",
454 "dom/base/test/chrome/window_nsITextInputProcessor.xhtml",
455 "dom/base/test/chrome/window_swapFrameLoaders.xhtml",
456 "dom/base/test/test_domrequesthelper.xhtml",
457 "dom/bindings/test/test_bug1123516_maplikesetlikechrome.xhtml",
458 "dom/console/tests/test_jsm.xhtml",
459 "dom/events/test/test_bug1412775.xhtml",
460 "dom/events/test/test_bug336682_2.xhtml",
461 "dom/events/test/test_bug415498.xhtml",
462 "dom/events/test/test_bug602962.xhtml",
463 "dom/events/test/test_bug617528.xhtml",
464 "dom/events/test/test_bug679494.xhtml",
465 "dom/indexedDB/test/test_globalObjects_chrome.xhtml",
466 "dom/indexedDB/test/test_wrappedArray.xhtml",
467 "dom/ipc/test.xhtml",
468 "dom/ipc/tests/test_process_error.xhtml",
469 "dom/notification/test/chrome/test_notification_system_principal.xhtml",
470 "dom/security/test/general/test_bug1277803.xhtml",
471 "dom/serviceworkers/test/test_serviceworkerinfo.xhtml",
472 "dom/serviceworkers/test/test_serviceworkermanager.xhtml",
473 "dom/system/tests/test_constants.xhtml",
474 "dom/tests/mochitest/chrome/DOMWindowCreated_chrome.xhtml",
475 "dom/tests/mochitest/chrome/MozDomFullscreen_chrome.xhtml",
476 "dom/tests/mochitest/chrome/sizemode_attribute.xhtml",
477 "dom/tests/mochitest/chrome/test_cyclecollector.xhtml",
478 "dom/tests/mochitest/chrome/test_docshell_swap.xhtml",
479 "dom/tests/mochitest/chrome/window_focus.xhtml",
480 "dom/url/tests/test_bug883784.xhtml",
481 "dom/workers/test/test_WorkerDebugger.xhtml",
482 "dom/workers/test/test_WorkerDebugger_console.xhtml",
483 "dom/workers/test/test_fileReadSlice.xhtml",
484 "dom/workers/test/test_fileReaderSync.xhtml",
485 "dom/workers/test/test_fileSlice.xhtml",
488 "mozilla/no-useless-parameters": "off",
489 "mozilla/no-useless-removeEventListener": "off",
490 "mozilla/use-chromeutils-generateqi": "off",
491 "mozilla/use-services": "off",
493 "no-array-constructor": "off",
497 "no-lone-blocks": "off",
498 "no-redeclare": "off",
500 "no-throw-literal": "off",
501 "no-unsanitized/method": "off",
502 "no-useless-return": "off",
503 "object-shorthand": "off",
512 "editor/libeditor/tests/**",
513 "editor/spellchecker/tests/test_bug338427.html",
515 "image/test/browser/browser_image.js",
522 "security/manager/**",
524 "storage/test/unit/test_vacuum.js",
525 "taskcluster/docker/periodic-updates/scripts/**",
528 "widget/tests/test_assign_event_data.html",
531 "mozilla/prefer-boolean-length-check": "off",
535 // TODO: Bug 1609271 Fix all violations for ChromeUtils.import(..., null)
537 "browser/base/content/test/sync/browser_fxa_web_channel.js",
538 "browser/components/customizableui/test/browser_1042100_default_placements_update.js",
539 "browser/components/customizableui/test/browser_1096763_seen_widgets_post_reset.js",
540 "browser/components/customizableui/test/browser_1161838_inserted_new_default_buttons.js",
541 "browser/components/customizableui/test/browser_989338_saved_placements_not_resaved.js",
542 "browser/components/customizableui/test/browser_currentset_post_reset.js",
543 "browser/components/customizableui/test/browser_panel_keyboard_navigation.js",
544 "browser/components/customizableui/test/browser_proton_toolbar_hide_toolbarbuttons.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",