From 167f623a3ecd2b1d5fa1f956d9bdd5fc6716e793 Mon Sep 17 00:00:00 2001 From: Ian Moody Date: Tue, 19 Mar 2019 22:02:42 +0000 Subject: [PATCH] Bug 1246594 - Enable ESLint rule no-throw-literal by default. r=Standard8 Differential Revision: https://phabricator.services.mozilla.com/D24088 --HG-- extra : moz-landing-system : lando --- .eslintrc.js | 55 +++++++++++++++++++ accessible/tests/browser/.eslintrc.js | 1 - browser/components/migration/.eslintrc.js | 1 - browser/components/newtab/.eslintrc.js | 1 - browser/components/payments/.eslintrc.js | 1 - browser/extensions/formautofill/.eslintrc.js | 4 -- .../webcompat-reporter/.eslintrc.js | 4 -- devtools/.eslintrc.js | 3 - .../extensions/report-site-issue/.eslintrc.js | 4 -- security/.eslintrc.js | 4 -- services/.eslintrc.js | 10 ---- .../docker/periodic-updates/.eslintrc.js | 4 -- toolkit/components/extensions/.eslintrc.js | 4 -- toolkit/components/narrate/.eslintrc.js | 1 - toolkit/components/satchel/.eslintrc.js | 1 - .../lib/configs/recommended.js | 4 ++ .../eslint-plugin-mozilla/package-lock.json | 2 +- .../eslint/eslint-plugin-mozilla/package.json | 2 +- 18 files changed, 61 insertions(+), 45 deletions(-) delete mode 100644 services/.eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js index a46359eb362b..10d4c83c42db 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -52,5 +52,60 @@ module.exports = { "rules": { "no-undef": "off", } + }, { + // TODO: Bug 1246594. Empty this list once the rule has landed for all dirs + "files": [ + "accessible/tests/mochitest/events.js", + "browser/actors/ContextMenuChild.jsm", + "browser/base/content/**", + "browser/components/customizableui/**", + "browser/components/enterprisepolicies/Policies.jsm", + "browser/components/places/content/**", + "browser/components/preferences/**", + "browser/components/privatebrowsing/test/browser/browser_privatebrowsing_cache.js", + "browser/components/urlbar/tests/browser/head-common.js", + "browser/extensions/fxmonitor/privileged/FirefoxMonitor.jsm", + "browser/modules/**", + "browser/tools/mozscreenshots/mozscreenshots/extension/TestRunner.jsm", + "docshell/test/chrome/docshell_helpers.js", + "docshell/test/navigation/NavigationUtils.js", + "dom/asmjscache/test/**", + "dom/cache/test/mochitest/test_cache_tons_of_fd.html", + "dom/crypto/test/**", + "dom/indexedDB/test/**", + "dom/localstorage/test/unit/test_migration.js", + "dom/plugins/test/mochitest/head.js", + "gfx/layers/apz/test/mochitest/**", + "mobile/android/components/**", + "mobile/android/modules/**", + "modules/libmar/tests/unit/head_libmar.js", + "netwerk/protocol/http/WellKnownOpportunisticUtils.jsm", + "netwerk/test/httpserver/httpd.js", + "netwerk/test/httpserver/test/**", + "parser/htmlparser/tests/mochitest/parser_datreader.js", + "testing/marionette/event.js", + "testing/mochitest/**", + "testing/modules/tests/xpcshell/test_assert.js", + "testing/specialpowers/content/specialpowersAPI.js", + "testing/talos/talos/**", + "toolkit/components/aboutmemory/content/aboutMemory.js", + "toolkit/components/captivedetect/test/unit/test_multiple_requests.js", + "toolkit/components/cleardata/ServiceWorkerCleanUp.jsm", + "toolkit/components/ctypes/**", + "toolkit/components/downloads/**", + "toolkit/components/places/tests/**", + "toolkit/components/processsingleton/MainProcessSingleton.jsm", + "toolkit/components/prompts/**", + "toolkit/components/search/SearchService.jsm", + "toolkit/components/telemetry/app/TelemetryEnvironment.jsm", + "toolkit/content/**", + "toolkit/modules/**", + "toolkit/mozapps/**", + "tools/leak-gauge/leak-gauge.html", + "xpcom/tests/unit/test_iniParser.js", + ], + "rules": { + "no-throw-literal": "off", + } }] }; diff --git a/accessible/tests/browser/.eslintrc.js b/accessible/tests/browser/.eslintrc.js index 30d3b41497bc..ed64c0bbc242 100644 --- a/accessible/tests/browser/.eslintrc.js +++ b/accessible/tests/browser/.eslintrc.js @@ -57,7 +57,6 @@ module.exports = { "no-shadow": "error", "no-sync": "off", "no-ternary": "off", - "no-throw-literal": "error", "no-underscore-dangle": "off", "no-undefined": "off", "no-unused-vars": ["error", {"vars": "all", "args": "none"}], diff --git a/browser/components/migration/.eslintrc.js b/browser/components/migration/.eslintrc.js index c7d9a1ed0b76..3f1e71431c4c 100644 --- a/browser/components/migration/.eslintrc.js +++ b/browser/components/migration/.eslintrc.js @@ -12,7 +12,6 @@ module.exports = { "no-multi-str": "error", "no-return-assign": "error", "no-shadow": "error", - "no-throw-literal": "error", "no-unused-vars": ["error", { "args": "after-used", "vars": "all" }], "semi-spacing": ["error", {"before": false, "after": true}], "space-in-parens": ["error", "never"], diff --git a/browser/components/newtab/.eslintrc.js b/browser/components/newtab/.eslintrc.js index 8619078502ec..834c48602ea1 100644 --- a/browser/components/newtab/.eslintrc.js +++ b/browser/components/newtab/.eslintrc.js @@ -185,7 +185,6 @@ module.exports = { "no-sync": 0, "no-template-curly-in-string": 2, "no-ternary": 0, - "no-throw-literal": 2, "no-undef-init": 2, "no-undefined": 0, "no-underscore-dangle": 0, diff --git a/browser/components/payments/.eslintrc.js b/browser/components/payments/.eslintrc.js index 6b6d0225f4cf..8cf11cb37655 100644 --- a/browser/components/payments/.eslintrc.js +++ b/browser/components/payments/.eslintrc.js @@ -51,7 +51,6 @@ module.exports = { max: 2, }], "no-proto": "error", - "no-throw-literal": "error", "no-unused-expressions": "error", "no-unused-vars": ["error", { args: "none", diff --git a/browser/extensions/formautofill/.eslintrc.js b/browser/extensions/formautofill/.eslintrc.js index 7501928dfe62..5c78e7b0a26a 100644 --- a/browser/extensions/formautofill/.eslintrc.js +++ b/browser/extensions/formautofill/.eslintrc.js @@ -88,10 +88,6 @@ module.exports = { // single line of code to have only one easily predictable effect. "no-return-assign": "error", - // Disallow throwing literals (eg. throw "error" instead of - // throw new Error("error")). - "no-throw-literal": "error", - // Require use of the second argument for parseInt(). "radix": "error", diff --git a/browser/extensions/webcompat-reporter/.eslintrc.js b/browser/extensions/webcompat-reporter/.eslintrc.js index 13ed5b289008..33d9b5915c9c 100644 --- a/browser/extensions/webcompat-reporter/.eslintrc.js +++ b/browser/extensions/webcompat-reporter/.eslintrc.js @@ -83,10 +83,6 @@ module.exports = { // single line of code to have only one easily predictable effect. "no-return-assign": "error", - // Disallow throwing literals (eg. throw "error" instead of - // throw new Error("error")). - "no-throw-literal": "error", - // Require use of the second argument for parseInt(). "radix": "error", diff --git a/devtools/.eslintrc.js b/devtools/.eslintrc.js index bebc3df5b192..5e94ff0591b0 100644 --- a/devtools/.eslintrc.js +++ b/devtools/.eslintrc.js @@ -330,9 +330,6 @@ module.exports = { "no-sync": "off", // Allow the use of ternary operators. "no-ternary": "off", - // Disallow throwing literals (eg. throw "error" instead of - // throw new Error("error")). - "no-throw-literal": "error", // Allow dangling underscores in identifiers (for privates). "no-underscore-dangle": "off", // Allow use of undefined variable. diff --git a/mobile/android/extensions/report-site-issue/.eslintrc.js b/mobile/android/extensions/report-site-issue/.eslintrc.js index 13ed5b289008..33d9b5915c9c 100644 --- a/mobile/android/extensions/report-site-issue/.eslintrc.js +++ b/mobile/android/extensions/report-site-issue/.eslintrc.js @@ -83,10 +83,6 @@ module.exports = { // single line of code to have only one easily predictable effect. "no-return-assign": "error", - // Disallow throwing literals (eg. throw "error" instead of - // throw new Error("error")). - "no-throw-literal": "error", - // Require use of the second argument for parseInt(). "radix": "error", diff --git a/security/.eslintrc.js b/security/.eslintrc.js index 1bab228b268e..5ab42bc8ae99 100644 --- a/security/.eslintrc.js +++ b/security/.eslintrc.js @@ -52,10 +52,6 @@ module.exports = { // Disallow use of this/super before calling super() in constructors. "no-this-before-super": "error", - // Disallow throwing literals (eg. |throw "error"| instead of - // |throw new Error("error")|) - "no-throw-literal": "error", - // Disallow unmodified loop conditions. "no-unmodified-loop-condition": "error", diff --git a/services/.eslintrc.js b/services/.eslintrc.js deleted file mode 100644 index 120e4d5de523..000000000000 --- a/services/.eslintrc.js +++ /dev/null @@ -1,10 +0,0 @@ -"use strict"; - -module.exports = { - plugins: [ - "mozilla" - ], - "rules": { - "no-throw-literal": 2, - }, -} diff --git a/taskcluster/docker/periodic-updates/.eslintrc.js b/taskcluster/docker/periodic-updates/.eslintrc.js index cc386f596767..043b9d082bd5 100644 --- a/taskcluster/docker/periodic-updates/.eslintrc.js +++ b/taskcluster/docker/periodic-updates/.eslintrc.js @@ -57,10 +57,6 @@ module.exports = { // Disallow use of this/super before calling super() in constructors. "no-this-before-super": "error", - // Disallow throwing literals (eg. |throw "error"| instead of - // |throw new Error("error")|) - "no-throw-literal": "error", - // Disallow unmodified loop conditions. "no-unmodified-loop-condition": "error", diff --git a/toolkit/components/extensions/.eslintrc.js b/toolkit/components/extensions/.eslintrc.js index 37c7f4fdb751..eb1cc862756b 100644 --- a/toolkit/components/extensions/.eslintrc.js +++ b/toolkit/components/extensions/.eslintrc.js @@ -229,10 +229,6 @@ module.exports = { // Allow the use of ternary operators. "no-ternary": "off", - // Disallow throwing literals (eg. throw "error" instead of - // throw new Error("error")). - "no-throw-literal": "error", - // Allow dangling underscores in identifiers (for privates). "no-underscore-dangle": "off", diff --git a/toolkit/components/narrate/.eslintrc.js b/toolkit/components/narrate/.eslintrc.js index 0bed7b56060d..4ec95ae3d64c 100644 --- a/toolkit/components/narrate/.eslintrc.js +++ b/toolkit/components/narrate/.eslintrc.js @@ -24,7 +24,6 @@ module.exports = { "no-multiple-empty-lines": ["error", {"max": 1}], "no-return-assign": "error", "no-shadow": "error", - "no-throw-literal": "error", "quotes": ["error", "double", "avoid-escape"], "semi-spacing": ["error", {"before": false, "after": true}], "space-in-parens": ["error", "never"], diff --git a/toolkit/components/satchel/.eslintrc.js b/toolkit/components/satchel/.eslintrc.js index c2cb599237d2..3f08e8610b97 100644 --- a/toolkit/components/satchel/.eslintrc.js +++ b/toolkit/components/satchel/.eslintrc.js @@ -37,7 +37,6 @@ module.exports = { max: 2, }], "no-proto": "error", - "no-throw-literal": "error", "no-unused-expressions": "error", "no-unused-vars": ["error", { args: "none", diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js index a615f82dc7d6..b73380385adb 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js @@ -286,6 +286,10 @@ module.exports = { // Disallow tabs. "no-tabs": "error", + // Disallow throwing literals (eg. throw "error" instead of + // throw new Error("error")). + "no-throw-literal": "error", + // No trailing whitespace "no-trailing-spaces": "error", diff --git a/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json b/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json index 5d1d94497336..08fe01ffab13 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json +++ b/tools/lint/eslint/eslint-plugin-mozilla/package-lock.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-mozilla", - "version": "1.1.2", + "version": "1.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/tools/lint/eslint/eslint-plugin-mozilla/package.json b/tools/lint/eslint/eslint-plugin-mozilla/package.json index ae7da6ccff12..b6e9648e0e7c 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/package.json +++ b/tools/lint/eslint/eslint-plugin-mozilla/package.json @@ -1,6 +1,6 @@ { "name": "eslint-plugin-mozilla", - "version": "1.1.2", + "version": "1.1.3", "description": "A collection of rules that help enforce JavaScript coding standard in the Mozilla project.", "keywords": [ "eslint",