Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the built-in class fields and private methods rules in ESLint 8 #14872

Merged
merged 14 commits into from Sep 13, 2022
33 changes: 26 additions & 7 deletions .github/workflows/ci.yml
Expand Up @@ -197,18 +197,15 @@ jobs:
- name: Downgrade Jest for node <= 10
if: matrix.node-version == '6' || matrix.node-version == '8' || matrix.node-version == '10'
run: |
yarn remove jest
yarn add --dev jest@24
yarn up jest@24
# Deduplicate dependencies, because duplicate copies of graceful-fs cause
# problems with the "path" module: https://github.com/facebook/jest/issues/9656
yarn dedupe
- name: Downgrade Jest for node == 12
- name: Downgrade Jest and jest-light-runner for node == 12
if: matrix.node-version == '12'
run: |
yarn remove jest
yarn remove jest-light-runner
yarn add --dev jest@28
yarn add --dev jest-light-runner@0.3.0
yarn up jest@28
yarn up jest-light-runner@0.3.0
# Deduplicate dependencies, because duplicate copies of graceful-fs cause
# problems with the "path" module: https://github.com/facebook/jest/issues/9656
yarn dedupe
Expand Down Expand Up @@ -430,3 +427,25 @@ jobs:
node-version: 16.6
- name: Test Node.js 16.6
run: yarn test:runtime:node

eslint7-test:
name: Test @babel/eslint-* with ESLint 7.5.0
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Use Node.js latest
uses: actions/setup-node@v3
with:
node-version: "*"
cache: "yarn"
- name: Install
run: yarn install
- uses: actions/download-artifact@v3
with:
name: babel-artifact
- name: Downgrade ESLint to 7.5.0
run: yarn up eslint@7.5.0
- name: Run babel/eslint tests
run: node ./node_modules/.bin/jest eslint
35 changes: 0 additions & 35 deletions babel.config.js
Expand Up @@ -67,7 +67,6 @@ module.exports = function (api) {
let ignoreLib = true;
let includeRegeneratorRuntime = false;
let needsPolyfillsForOldNode = false;
let dynamicESLintVersionCheck = false;

let transformRuntimeOptions;

Expand Down Expand Up @@ -118,7 +117,6 @@ module.exports = function (api) {
needsPolyfillsForOldNode = true;
break;
case "test-legacy": // In test-legacy environment, we build babel on latest node but test on minimum supported legacy versions
dynamicESLintVersionCheck = true;
// fall through
case "production":
// Config during builds before publish.
Expand All @@ -128,12 +126,10 @@ module.exports = function (api) {
case "test":
targets = { node: "current" };
needsPolyfillsForOldNode = true;
dynamicESLintVersionCheck = true;
break;
case "development":
envOpts.debug = true;
targets = { node: "current" };
dynamicESLintVersionCheck = true;
break;
}

Expand Down Expand Up @@ -291,10 +287,6 @@ module.exports = function (api) {
exclude: /regenerator-runtime/,
plugins: [["@babel/transform-runtime", transformRuntimeOptions]],
},
dynamicESLintVersionCheck && {
test: ["./eslint/*/src"].map(normalize),
plugins: [pluginDynamicESLintVersionCheck],
},
].filter(Boolean),
};

Expand Down Expand Up @@ -815,33 +807,6 @@ function pluginBabelParserTokenType({
};
}

// Transforms
// ESLINT_VERSION
// to
// process.env.ESLINT_VERSION_FOR_BABEL
// ? parseInt(process.env.ESLINT_VERSION_FOR_BABEL, 10)
// : ESLINT_VERSION
function pluginDynamicESLintVersionCheck({ template }) {
const transformed = new WeakSet();

return {
visitor: {
ReferencedIdentifier(path) {
if (path.node.name !== "ESLINT_VERSION") return;

if (transformed.has(path.node)) return;
transformed.add(path.node);

path.replaceWith(template.expression.ast`
process.env.ESLINT_VERSION_FOR_BABEL
? parseInt(process.env.ESLINT_VERSION_FOR_BABEL, 10)
: ${path.node}
`);
},
},
};
}

// Inject `0 && exports.foo = 0` hints for the specified exports,
// to help the Node.js CJS-ESM interop. This is only
// needed when compiling ESM re-exports to CJS in `lazy` mode.
Expand Down
8 changes: 4 additions & 4 deletions eslint/babel-eslint-parser/package.json
Expand Up @@ -31,14 +31,14 @@
"eslint": "^7.5.0 || ^8.0.0"
},
"dependencies": {
"eslint-scope": "^5.1.1",
"eslint-visitor-keys": "^2.1.0",
"@nicolo-ribaudo/eslint-scope-5-internals": "condition:BABEL_8_BREAKING ? : 5.1.1-v1",
"eslint-scope": "condition:BABEL_8_BREAKING ? ^7.1.1 : ",
"eslint-visitor-keys": "condition:BABEL_8_BREAKING ? ^3.3.0 : ^2.1.0",
"semver": "condition:BABEL_8_BREAKING ? ^7.3.4 : ^6.3.0"
},
"devDependencies": {
"@babel/core": "workspace:^",
"dedent": "^0.7.0",
"eslint": "^7.27.0",
"eslint-8": "npm:eslint@^8.0.0"
"eslint": "^8.22.0"
}
}
17 changes: 11 additions & 6 deletions eslint/babel-eslint-parser/src/analyze-scope.cjs
@@ -1,7 +1,12 @@
const escope = require("eslint-scope");
const { Definition } = require("eslint-scope/lib/definition");
const OriginalPatternVisitor = require("eslint-scope/lib/pattern-visitor");
const OriginalReferencer = require("eslint-scope/lib/referencer");
const {
Definition,
PatternVisitor: OriginalPatternVisitor,
Referencer: OriginalReferencer,
Scope,
ScopeManager,
} = process.env.BABEL_8_BREAKING
? require("eslint-scope")
: require("@nicolo-ribaudo/eslint-scope-5-internals");
const { getKeys: fallback } = require("eslint-visitor-keys");

let visitorKeysMap;
Expand Down Expand Up @@ -236,7 +241,7 @@ class Referencer extends OriginalReferencer {
}

const parentScope = this.scopeManager.__currentScope;
const scope = new escope.Scope(
const scope = new Scope(
this.scopeManager,
"type-parameters",
parentScope,
Expand Down Expand Up @@ -349,7 +354,7 @@ module.exports = function analyzeScope(ast, parserOptions, client) {

options.childVisitorKeys = client.getVisitorKeys();

const scopeManager = new escope.ScopeManager(options);
const scopeManager = new ScopeManager(options);
const referencer = new Referencer(options, scopeManager, client);

referencer.visit(ast);
Expand Down