From 56cc7346e118d0fcfbbb43d371a21165484743e4 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Fri, 2 Feb 2024 18:45:08 +0000 Subject: [PATCH] Bug 1878009 - Remove Babel integration from ESLint. r=mossop,devtools-reviewers,nchevobbe Differential Revision: https://phabricator.services.mozilla.com/D200365 --- .eslintrc.js | 19 +++++---- devtools/.eslintrc.js | 10 +++++ devtools/client/debugger/src/.eslintrc.js | 9 +---- toolkit/content/.eslintrc.js | 13 ++++-- .../lib/configs/recommended.js | 5 ++- .../eslint-plugin-mozilla/lib/helpers.js | 40 +++++-------------- tools/lint/eslint/setup_helper.py | 4 -- 7 files changed, 47 insertions(+), 53 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index e942a878c8b1..777dfbb67747 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -55,13 +55,6 @@ const httpTestingPaths = [ ]; module.exports = { - parser: "@babel/eslint-parser", - parserOptions: { - sourceType: "script", - babelOptions: { - configFile: path.join(__dirname, ".babel-eslint.rc.js"), - }, - }, settings: { "import/extensions": [".mjs"], }, @@ -84,6 +77,18 @@ module.exports = { browser: false, }, }, + { + files: [ + "**/*.jsx", + "browser/components/pocket/content/**/*.js", + "browser/components/storybook/.storybook/**/*.mjs", + ], + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + }, { files: ["browser/components/storybook/**"], env: { diff --git a/devtools/.eslintrc.js b/devtools/.eslintrc.js index 386ae14cd105..9b1deba0202d 100644 --- a/devtools/.eslintrc.js +++ b/devtools/.eslintrc.js @@ -155,6 +155,16 @@ module.exports = { "mozilla/specific": false, }, }, + { + files: [ + "client/inspector/markup/test/doc_markup_events_react_*_jsx.html", + ], + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + }, + }, ], rules: { // These are the rules that have been configured so far to match the diff --git a/devtools/client/debugger/src/.eslintrc.js b/devtools/client/debugger/src/.eslintrc.js index eedd63c412e5..cb7cb7cb2f95 100644 --- a/devtools/client/debugger/src/.eslintrc.js +++ b/devtools/client/debugger/src/.eslintrc.js @@ -3,7 +3,7 @@ * file, You can obtain one at . */ module.exports = { - plugins: ["react", "mozilla", "@babel", "import", "file-header"], + plugins: ["react", "mozilla", "import", "file-header"], globals: { atob: true, btoa: true, @@ -32,13 +32,6 @@ module.exports = { ecmaVersion: "latest", sourceType: "module", ecmaFeatures: { jsx: true }, - - // When the linter runs from the MC root, it won't pick up this project's - // babel.config.js, so we explicitly set Babel's root location so that - // it knows where to look. - babelOptions: { - root: __dirname, - }, }, env: { es6: true, diff --git a/toolkit/content/.eslintrc.js b/toolkit/content/.eslintrc.js index ea5a72ce6723..b56cafb08b90 100644 --- a/toolkit/content/.eslintrc.js +++ b/toolkit/content/.eslintrc.js @@ -5,10 +5,15 @@ "use strict"; module.exports = { - env: { - "mozilla/browser-window": true, - }, - + overrides: [ + { + files: "./**/*.?(m)js", + excludedFiles: "aboutwebrtc/**", + env: { + "mozilla/browser-window": true, + }, + }, + ], plugins: ["mozilla"], rules: { 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 cedd0aaf59a7..0bb161e4dca1 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/configs/recommended.js @@ -14,7 +14,7 @@ module.exports = { env: { browser: true, - es2021: true, + es2022: true, "mozilla/privileged": true, "mozilla/specific": true, }, @@ -83,6 +83,9 @@ module.exports = { }, { files: ["**/*.mjs"], + parserOptions: { + sourceType: "module", + }, rules: { "mozilla/use-static-import": "error", // This rule defaults to not allowing "use strict" in module files since diff --git a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js index c74253b7710f..dc4106631a48 100644 --- a/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js +++ b/tools/lint/eslint/eslint-plugin-mozilla/lib/helpers.js @@ -6,7 +6,7 @@ */ "use strict"; -const parser = require("@babel/eslint-parser"); +const parser = require("espree"); const { analyze } = require("eslint-scope"); const { KEYS: defaultVisitorKeys } = require("eslint-visitor-keys"); const estraverse = require("estraverse"); @@ -96,18 +96,19 @@ module.exports = { // can parse. let config = { ...this.getPermissiveConfig(configOptions), ...astOptions }; - let parseResult = - "parseForESLint" in parser - ? parser.parseForESLint(sourceText, config) - : { ast: parser.parse(sourceText, config) }; + let parseResult = parser.parse(sourceText, config); let visitorKeys = parseResult.visitorKeys || defaultVisitorKeys; - visitorKeys.ExperimentalRestProperty = visitorKeys.RestElement; - visitorKeys.ExperimentalSpreadProperty = visitorKeys.SpreadElement; + + // eslint-scope doesn't support "latest" as a version, so we pass a really + // big number to ensure this always reads as the latest. + // xref https://github.com/eslint/eslint-scope/issues/74 + config.ecmaVersion = + config.ecmaVersion == "latest" ? 1e8 : config.ecmaVersion; return { - ast: parseResult.ast, - scopeManager: parseResult.scopeManager || analyze(parseResult.ast), + ast: parseResult, + scopeManager: parseResult.scopeManager || analyze(parseResult, config), visitorKeys, }; }, @@ -285,33 +286,14 @@ module.exports = { * Espree compatible permissive config. */ getPermissiveConfig({ useBabel = true } = {}) { - const config = { + return { range: true, - requireConfigFile: false, - babelOptions: { - // configFile: path.join(gRootDir, ".babel-eslint.rc.js"), - // parserOpts: { - // plugins: [ - // "@babel/plugin-proposal-class-static-block", - // "@babel/plugin-syntax-class-properties", - // "@babel/plugin-syntax-jsx", - // ], - // }, - }, loc: true, comment: true, attachComment: true, ecmaVersion: this.getECMAVersion(), sourceType: "script", }; - - if (useBabel && this.isMozillaCentralBased()) { - config.babelOptions.configFile = path.join( - gRootDir, - ".babel-eslint.rc.js" - ); - } - return config; }, /** diff --git a/tools/lint/eslint/setup_helper.py b/tools/lint/eslint/setup_helper.py index 4a7d39a9b08b..2f2074d2cfad 100644 --- a/tools/lint/eslint/setup_helper.py +++ b/tools/lint/eslint/setup_helper.py @@ -214,10 +214,6 @@ def expected_eslint_modules(): ) with open(mozilla_json_path, encoding="utf-8") as f: dependencies = json.load(f).get("dependencies", {}) - # Bug 1860508: We skip checking eslint-visitor-keys because the Babel - # dependencies currently require an older version to that which - # eslint-plugin-mozilla requires. - dependencies.pop("eslint-visitor-keys") expected_modules.update(dependencies) # Also read the in-tree ESLint plugin spidermonkey information, to ensure the