Skip to content

Commit

Permalink
Use eslint v9 (#16479)
Browse files Browse the repository at this point in the history
* update

* skip old eslint

* review

* compat
  • Loading branch information
liuxingbaoyu committed May 10, 2024
1 parent c1bf7d7 commit e37e64d
Show file tree
Hide file tree
Showing 31 changed files with 196 additions and 246 deletions.
4 changes: 2 additions & 2 deletions Makefile.js

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions Makefile.source.mjs
Expand Up @@ -336,7 +336,6 @@ target["clone-license"] = function () {
*/

function eslint(...extraArgs) {
const eslintEnv = { BABEL_ENV: "test" };
const eslintArgs = ["--format", "codeframe", ...extraArgs.filter(Boolean)];

const packagesPackages = readdirSync("packages").filter(n =>
Expand All @@ -361,10 +360,15 @@ function eslint(...extraArgs) {

if (process.env.ESLINT_GO_BRRRR) {
// Run as a single process. Needs a lot of memory (12GB).
env(() => yarn(["eslint", "packages", ...rest, ...eslintArgs]), eslintEnv);
env(() => yarn(["eslint", "packages", ...rest, ...eslintArgs]), {
BABEL_ENV: "test",
NODE_OPTIONS: "--max-old-space-size=16384",
});
} else {
for (const chunk of chunks) {
env(() => yarn(["eslint", ...chunk, ...eslintArgs]), eslintEnv);
env(() => yarn(["eslint", ...chunk, ...eslintArgs]), {
BABEL_ENV: "test",
});
}
}
}
Expand Down
19 changes: 8 additions & 11 deletions eslint.config.js
Expand Up @@ -65,7 +65,7 @@ module.exports = [
{
plugins: {
import: pluginImport,
node: pluginN,
n: pluginN,
prettier: pluginPrettier,
"@babel/development": pluginBabelDevelopment,
"@babel/development-internal": pluginBabelDevelopmentInternal,
Expand All @@ -85,7 +85,10 @@ module.exports = [
parser: typescriptEslint.parser,
parserOptions: {
allowAutomaticSingleRunInference: true,
EXPERIMENTAL_useProjectService: true,
// @ts-expect-error types are old
EXPERIMENTAL_useProjectService: {
maximumDefaultProjectFileMatchCount_THIS_WILL_SLOW_DOWN_LINTING: 1000,
},
},
},
plugins: {
Expand Down Expand Up @@ -218,9 +221,9 @@ module.exports = [
{
files: testFiles,
rules: {
"node/no-unsupported-features": [
"n/no-unsupported-features/node-builtins": [
"error",
{ version: "12.17.0", ignores: ["modules"] },
{ version: "12.17.0", ignores: ["module"] },
],
"@babel/development-internal/require-default-import-fallback": "error",
"import/no-unresolved": "error",
Expand Down Expand Up @@ -281,12 +284,6 @@ module.exports = [
],
},
},
{
files: ["eslint/babel-eslint-parser/src/**/*.js"],
rules: {
"no-restricted-imports": ["error", "@babel/core"],
},
},
{
files: ["packages/babel-plugin-transform-runtime/scripts/**/*.js"],
rules: {
Expand All @@ -306,7 +303,7 @@ module.exports = [
},
},
{
files: ["scripts/**/*.{js,cjs}"],
files: ["scripts/**/*.{js,cjs,mjs}"],
rules: {
"import/no-extraneous-dependencies": ["error", { packageDir: "." }],
},
Expand Down
1 change: 1 addition & 0 deletions eslint/babel-eslint-config-internal/index.js
Expand Up @@ -34,6 +34,7 @@ module.exports = [
"no-confusing-arrow": "error",
"no-empty": ["error", { allowEmptyCatch: true }],
"no-process-exit": "error",
"no-unused-vars": ["error", { caughtErrors: "none" }],
"no-var": "error",
"prefer-const": "error",
},
Expand Down
1 change: 0 additions & 1 deletion eslint/babel-eslint-parser/src/types.d.cts
Expand Up @@ -3,7 +3,6 @@ import type { InputOptions } from "@babel/core";
import type { Token as tokenizerToken } from "../../../packages/babel-parser/src/tokenizer";
import type { ExportedTokenType } from "../../../packages/babel-parser/src/tokenizer/types";
import type * as estree from "estree";
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type {
PatternVisitor,
Reference,
Expand Down
Expand Up @@ -33,7 +33,9 @@ module.exports = {
);
if (!defaultSpecifier) return;

const scope = ctx.getScope();
const scope = ctx.sourceCode
? ctx.sourceCode.getScope(node)
: ctx.getScope();

const { name: local } = defaultSpecifier.local;
const { references } = scope.variables.find(v => v.name === local);
Expand Down
Expand Up @@ -10,7 +10,9 @@ module.exports = {
return {
CallExpression(node) {
const { callee } = node;
const scope = context.getScope();
const scope = context.sourceCode
? context.sourceCode.getScope(node)
: context.getScope();

const origin = getReferenceOrigin(callee, scope);
if (!origin) return;
Expand Down
Expand Up @@ -17,7 +17,9 @@ module.exports = {
return {
CallExpression(node) {
const { callee } = node;
const scope = context.getScope();
const scope = context.sourceCode
? context.sourceCode.getScope(node)
: context.getScope();

const origin = getReferenceOrigin(callee, scope);
if (!origin) return;
Expand Down
11 changes: 10 additions & 1 deletion eslint/babel-eslint-plugin-development/src/rules/plugin-name.cjs
Expand Up @@ -32,7 +32,16 @@ module.exports = {
};

function functionVisitor(node) {
if (!isBabelPluginFactory(node, context.getScope())) return;
if (
!isBabelPluginFactory(
node,
context.sourceCode
? context.sourceCode.getScope(node)
: context.getScope(),
)
) {
return;
}

const returnValue = getReturnValue(node);
if (!returnValue || returnValue.type !== "ObjectExpression") return;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -51,12 +51,12 @@
"c8": "^8.0.1",
"charcodes": "^0.2.0",
"core-js": "^3.36.1",
"eslint": "^8.57.0",
"eslint": "^9.2.0",
"eslint-formatter-codeframe": "^7.32.1",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-n": "^17.5.0",
"eslint-plugin-prettier": "^5.1.3",
"execa": "^8.0.1",
"glob": "^10.3.10",
Expand All @@ -82,8 +82,8 @@
"shelljs": "^0.8.5",
"test262-stream": "^1.4.0",
"through2": "^4.0.0",
"typescript": "^5.4.2",
"typescript-eslint": "^7.2.0"
"typescript": "^5.4.5",
"typescript-eslint": "^7.8.0"
},
"workspaces": [
"codemods/*",
Expand Down
1 change: 0 additions & 1 deletion packages/babel-cli/src/babel/dir.ts
Expand Up @@ -167,7 +167,6 @@ export default async function ({
for (const filename of cliOptions.filenames) {
// compiledFiles is just incremented without reading its value, so we
// don't risk race conditions.
// eslint-disable-next-line require-atomic-updates
compiledFiles += await handle(filename);
}

Expand Down
1 change: 0 additions & 1 deletion packages/babel-core/src/config/files/module-types.ts
Expand Up @@ -195,7 +195,6 @@ const loadMjsDefault = endHiddenCallStack(async function loadMjsDefault(

function getTSPreset(filepath: string) {
try {
// eslint-disable-next-line import/no-extraneous-dependencies
return require("@babel/preset-typescript");
} catch (error) {
if (error.code !== "MODULE_NOT_FOUND") throw error;
Expand Down
1 change: 0 additions & 1 deletion packages/babel-core/src/errors/rewrite-stack-trace.ts
Expand Up @@ -119,7 +119,6 @@ export function endHiddenCallStack<A extends unknown[], R>(

function setupPrepareStackTrace() {
// @ts-expect-error This function is a singleton
// eslint-disable-next-line no-func-assign
setupPrepareStackTrace = () => {};

const { prepareStackTrace = defaultPrepareStackTrace } = Error;
Expand Down
Expand Up @@ -281,7 +281,7 @@ const privateNameVisitor = privateNameVisitorFactory<
}
const { name } = node.id;
if (!privateNamesMap.has(name)) return;
if (redeclared && redeclared.includes(name)) return;
if (redeclared?.includes(name)) return;

this.handle(parentPath, noDocumentAll);
},
Expand Down Expand Up @@ -333,7 +333,7 @@ const privateInVisitor = privateNameVisitorFactory<
const { name } = left.id;

if (!privateNamesMap.has(name)) return;
if (redeclared && redeclared.includes(name)) return;
if (redeclared?.includes(name)) return;

// if there are any local variable shadowing classRef, unshadow it
// see #12960
Expand Down
Expand Up @@ -15,7 +15,6 @@ if (!process.env.BABEL_8_BREAKING) {
const originalGetModuleName = getModuleName;

// @ts-expect-error TS doesn't like reassigning a function.
// eslint-disable-next-line no-func-assign
getModuleName = function getModuleName(
rootOpts: RootOptions & PluginOptions,
pluginOpts: PluginOptions,
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-helpers/src/helpers/typeof.js
@@ -1,7 +1,5 @@
/* @minVersion 7.0.0-beta.0 */

/* eslint-disable no-func-assign */

export default function _typeof(obj) {
"@babel/helpers - typeof";

Expand Down
3 changes: 1 addition & 2 deletions packages/babel-helpers/src/helpers/usingCtx.ts
Expand Up @@ -9,8 +9,7 @@ type Stack = {
export default function _usingCtx() {
var _disposeSuppressedError =
typeof SuppressedError === "function"
? // eslint-disable-next-line no-undef
SuppressedError
? SuppressedError
: (function (error: Error, suppressed: Error) {
var err = new Error() as SuppressedError;
err.name = "SuppressedError";
Expand Down
1 change: 0 additions & 1 deletion packages/babel-parser/src/parser/expression.ts
Expand Up @@ -2652,7 +2652,6 @@ export default abstract class ExpressionParser extends LValParser {
checkParams(
node: Undone<N.Function>,
allowDuplicates: boolean,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
isArrowFunction?: boolean | null,
strictModeChanged: boolean = true,
): void {
Expand Down
4 changes: 1 addition & 3 deletions packages/babel-parser/src/parser/statement.ts
Expand Up @@ -2397,7 +2397,6 @@ export default abstract class StatementParser extends ExpressionParser {
this.unexpected(null, tt.braceL);
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
eatExportStar(
node: Undone<N.Node>,
): node is Undone<N.ExportNamedDeclaration | N.ExportAllDeclaration> {
Expand Down Expand Up @@ -3387,11 +3386,10 @@ export default abstract class StatementParser extends ExpressionParser {
parseImportSpecifier(
specifier: Undone<N.ImportSpecifier>,
importedIsString: boolean,
/* eslint-disable @typescript-eslint/no-unused-vars -- used in TypeScript and Flow parser */
/* used in TypeScript and Flow parser */
isInTypeOnlyImport: boolean,
isMaybeTypeOnly: boolean,
bindingType: BindingFlag | undefined,
/* eslint-enable @typescript-eslint/no-unused-vars */
): N.ImportSpecifier {
if (this.eatContextual(tt._as)) {
specifier.local = this.parseIdentifier();
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-parser/src/plugins/flow/index.ts
Expand Up @@ -2205,7 +2205,6 @@ export default (superClass: typeof Parser) =>

parseParenItem<T extends N.Expression | N.RestElement | N.SpreadElement>(
node: T,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
startLoc: Position,
): T | N.TypeCastExpression | N.TsTypeCastExpression {
const newNode = super.parseParenItem(node, startLoc);
Expand Down Expand Up @@ -2444,7 +2443,6 @@ export default (superClass: typeof Parser) =>
exprList:
| ReadonlyArray<N.Expression | N.SpreadElement>
| ReadonlyArray<N.Expression | N.RestElement>,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
isParenthesizedExpr?: boolean,
):
| ReadonlyArray<N.Expression | N.SpreadElement>
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-parser/src/plugins/placeholders.ts
Expand Up @@ -35,8 +35,6 @@ const PlaceholderErrors = ParseErrorEnum`placeholders`({
UnexpectedSpace: "Unexpected space in placeholder.",
});

/* eslint-disable sort-keys */

export default (superClass: typeof Parser) =>
class PlaceholdersParserMixin extends superClass implements Parser {
parsePlaceholder<T extends PlaceholderTypes>(
Expand Down
1 change: 0 additions & 1 deletion packages/babel-parser/src/util/scopeflags.ts
@@ -1,5 +1,4 @@
// Each scope gets a bitset that may contain these flags
/* eslint-disable prettier/prettier */
/* prettier-ignore */
export const enum ScopeFlag {
OTHER = 0b000000000,
Expand Down
3 changes: 1 addition & 2 deletions packages/babel-parser/test/helpers/run-fixture-tests.js
Expand Up @@ -118,7 +118,6 @@ function runParseTest(parse, test, onlyCompareErrors) {
const optionsLocation = join(testLocation, "options.json");

// We want to throw away the contents of `throws` here.
// eslint-disable-next-line no-unused-vars
const { throws: expectedThrows, ...oldOptions } = readJSON(optionsLocation);
const newOptions = { ...oldOptions, ...(throws && { throws }) };

Expand Down Expand Up @@ -176,7 +175,7 @@ function runParseTest(parse, test, onlyCompareErrors) {
function readJSON(filename) {
try {
return JSONParse(readFileSync(filename, "utf-8"));
} catch (error) {
} catch {
return {};
}
}
Expand Down
Expand Up @@ -119,7 +119,7 @@ export default declare((api, options: Options) => {
// Ignore constant bindings.
if (path.isIdentifier()) {
const binding = path.scope.getBinding(path.node.name);
if (binding && binding.constant) return;
if (binding?.constant) return;
}

// If we allow mutable props, tags with function expressions can be
Expand Down
2 changes: 0 additions & 2 deletions packages/babel-plugin-transform-runtime/scripts/build-dist.js
Expand Up @@ -83,7 +83,6 @@ if (!bool(process.env.BABEL_8_BREAKING)) {
corejsRoot: "core-js-pure/features",
});

// eslint-disable-next-line no-inner-declarations
function writeCoreJS({
corejs,
proposals,
Expand Down Expand Up @@ -124,7 +123,6 @@ if (!bool(process.env.BABEL_8_BREAKING)) {
writeCorejsExports(pkgDirname, runtimeRoot, paths);
}

// eslint-disable-next-line no-inner-declarations
function writeCorejsExports(pkgDirname, runtimeRoot, paths) {
const pkgJsonPath = require.resolve(`${pkgDirname}/package.json`);
const pkgJson = require(pkgJsonPath);
Expand Down
8 changes: 4 additions & 4 deletions packages/babel-traverse/src/path/family.ts
Expand Up @@ -10,8 +10,8 @@ import {
} from "@babel/types";
import type * as t from "@babel/types";

const NORMAL_COMPLETION = 0 as const;
const BREAK_COMPLETION = 1 as const;
const NORMAL_COMPLETION = 0;
const BREAK_COMPLETION = 1;

type Completion = {
path: NodePath;
Expand All @@ -30,11 +30,11 @@ type CompletionContext = {
shouldPopulateBreak: boolean;
};

function NormalCompletion(path: NodePath) {
function NormalCompletion(path: NodePath): Completion {
return { type: NORMAL_COMPLETION, path };
}

function BreakCompletion(path: NodePath) {
function BreakCompletion(path: NodePath): Completion {
return { type: BREAK_COMPLETION, path };
}

Expand Down
2 changes: 1 addition & 1 deletion packages/babel-traverse/src/scope/index.ts
Expand Up @@ -440,7 +440,7 @@ export default class Scope {
const shouldSkip = path.key === "key" || path.listKey === "decorators";
path = path.parentPath;
if (shouldSkip && path.isMethod()) path = path.parentPath;
if (path && path.isScope()) parent = path;
if (path?.isScope()) parent = path;
} while (path && !parent);

return parent?.scope;
Expand Down
1 change: 0 additions & 1 deletion packages/babel-traverse/src/visitors.ts
Expand Up @@ -138,7 +138,6 @@ export function explode<S>(visitor: Visitor<S>): ExplodedVisitor<S> {
if (existing) {
mergePair(existing, fns);
} else {
// @ts-expect-error Expression produces a union type that is too complex to represent.
visitor[alias] = { ...fns };
}
}
Expand Down

0 comments on commit e37e64d

Please sign in to comment.