Skip to content

Commit

Permalink
Update typescript and lint tools (babel#16351)
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Mar 14, 2024
1 parent 91d2158 commit fc0d5ad
Show file tree
Hide file tree
Showing 7 changed files with 759 additions and 655 deletions.
171 changes: 83 additions & 88 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-check
"use strict";

const configInternal = require("@babel/eslint-config-internal");
Expand All @@ -6,8 +7,7 @@ const pluginN = require("eslint-plugin-n");
const pluginPrettier = require("eslint-plugin-prettier");
const pluginBabelDevelopment = require("@babel/eslint-plugin-development");
const pluginBabelDevelopmentInternal = require("@babel/eslint-plugin-development-internal");
const pluginTypeScriptESLint = require("@typescript-eslint/eslint-plugin");
const parserTypeScriptESLint = require("@typescript-eslint/parser");
const typescriptEslint = require("typescript-eslint");

const { FlatCompat } = require("@eslint/eslintrc");

Expand Down Expand Up @@ -75,97 +75,92 @@ module.exports = [
"import/no-extraneous-dependencies": "error",
},
},
...compat
.extends(
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked"
)
.map(config => {
return {
...config,
files: ["**/*.{ts,cts}"],
languageOptions: {
parser: parserTypeScriptESLint,
parserOptions: {
allowAutomaticSingleRunInference: true,
EXPERIMENTAL_useProjectService: true,
...typescriptEslint.config({
files: ["**/*.{ts,cts}"],
extends: [
...typescriptEslint.configs.recommendedTypeChecked,
...typescriptEslint.configs.stylisticTypeChecked,
],
languageOptions: {
parser: typescriptEslint.parser,
parserOptions: {
allowAutomaticSingleRunInference: true,
EXPERIMENTAL_useProjectService: true,
},
},
plugins: {
"@typescript-eslint": typescriptEslint.plugin,
},
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"no-dupe-class-members": "off",
"@typescript-eslint/no-dupe-class-members": "error",
"no-undef": "off",
"no-redeclare": "off",
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": {
descriptionFormat: "^\\(Babel 7 vs Babel 8\\) .+$",
},
},
plugins: {
"@typescript-eslint": pluginTypeScriptESLint,
],
"@typescript-eslint/consistent-type-imports": [
"error",
{ disallowTypeAnnotations: false },
],
"@typescript-eslint/no-use-before-define": [
"error",
{
functions: false,
classes: false,
allowNamedExports: true,
},
rules: {
...config.rules,
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"no-dupe-class-members": "off",
"@typescript-eslint/no-dupe-class-members": "error",
"no-undef": "off",
"no-redeclare": "off",
"@typescript-eslint/ban-ts-comment": [
"error",
{
"ts-ignore": {
descriptionFormat: "^\\(Babel 7 vs Babel 8\\) .+$",
},
},
],
"@typescript-eslint/consistent-type-imports": [
"error",
{ disallowTypeAnnotations: false },
],
"@typescript-eslint/no-use-before-define": [
"error",
{
functions: false,
classes: false,
allowNamedExports: true,
},
],
"@typescript-eslint/no-confusing-void-expression": [
"error",
{ ignoreArrowShorthand: true },
],
"@typescript-eslint/no-import-type-side-effects": "error",
],
"@typescript-eslint/no-confusing-void-expression": [
"error",
{ ignoreArrowShorthand: true },
],
"@typescript-eslint/no-import-type-side-effects": "error",

// Todo: Investigate, for each of these, whether we want them
"@typescript-eslint/array-type": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-generic-constructors": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/no-duplicate-type-constituents": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-declaration-merging": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/prefer-function-type": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/prefer-string-starts-ends-with": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/sort-type-constituents": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/unbound-method": "off",
"prefer-rest-params": "off",
// Todo: Investigate, for each of these, whether we want them
"@typescript-eslint/array-type": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-generic-constructors": "off",
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/dot-notation": "off",
"@typescript-eslint/no-base-to-string": "off",
"@typescript-eslint/no-duplicate-type-constituents": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-empty-interface": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-this-alias": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-declaration-merging": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-var-requires": "off",
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/prefer-function-type": "off",
"@typescript-eslint/prefer-nullish-coalescing": "off",
"@typescript-eslint/prefer-string-starts-ends-with": "off",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/sort-type-constituents": "off",
"@typescript-eslint/triple-slash-reference": "off",
"@typescript-eslint/unbound-method": "off",
"prefer-rest-params": "off",

// https://github.com/typescript-eslint/typescript-eslint/issues/5014
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
},
};
}),
// https://github.com/typescript-eslint/typescript-eslint/issues/5014
"@typescript-eslint/no-inferrable-types": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-return": "off",
},
}),
{
files: sourceFiles("js,ts,cjs,mjs"),
languageOptions: {
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,19 @@
"@rollup/plugin-terser": "^0.4.4",
"@types/jest": "^29.5.11",
"@types/node": "^20.11.5",
"@typescript-eslint/eslint-plugin": "^6.15.0",
"@typescript-eslint/parser": "^6.15.0",
"@yarnpkg/types": "^4.0.0",
"babel-plugin-transform-charcodes": "^0.2.0",
"c8": "^8.0.1",
"chalk": "^5.3.0",
"charcodes": "^0.2.0",
"core-js": "^3.31.1",
"eslint": "^8.56.0",
"eslint": "^8.57.0",
"eslint-formatter-codeframe": "^7.32.1",
"eslint-import-resolver-node": "^0.3.9",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^27.6.0",
"eslint-plugin-n": "^16.5.0",
"eslint-plugin-prettier": "^5.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^27.9.0",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-prettier": "^5.1.3",
"glob": "^10.3.10",
"gulp": "^4.0.2",
"gulp-filter": "^7.0.0",
Expand All @@ -73,7 +71,7 @@
"jest-worker": "^30.0.0-alpha.2",
"lint-staged": "^15.2.0",
"mergeiterator": "^1.4.4",
"prettier": "^3.1.1",
"prettier": "^3.2.5",
"rollup": "^4.9.1",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-dts-5": "npm:rollup-plugin-dts@^5.3.1",
Expand All @@ -82,7 +80,8 @@
"shelljs": "^0.8.5",
"test262-stream": "^1.4.0",
"through2": "^4.0.0",
"typescript": "5.4.0-dev.20240125"
"typescript": "^5.4.2",
"typescript-eslint": "^7.2.0"
},
"workspaces": [
"codemods/*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ interface Support {

const SUPPORT_CACHE = new WeakMap<Targets, Support>();
export default function getSupport(targets: Targets): Support {
if (SUPPORT_CACHE.has(targets)) return SUPPORT_CACHE.get(targets)!;
if (SUPPORT_CACHE.has(targets)) return SUPPORT_CACHE.get(targets);

const { node: nodeTarget, ...webTargets } = targets;
const emptyNodeTarget = nodeTarget == null;
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-helper-string-parser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function readEscapedChar(
default:
if (ch >= charCodes.digit0 && ch <= charCodes.digit7) {
const startPos = pos - 1;
const match = input.slice(startPos, pos + 2).match(/^[0-7]+/)!;
const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);

let octalStr = match[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ export const UnparenthesizedPipeBodyDescriptions = new Set([
"YieldExpression",
] as const);

type GetSetMemberType<T extends Set<any>> = T extends Set<infer M>
? M
: unknown;
type GetSetMemberType<T extends Set<any>> =
T extends Set<infer M> ? M : unknown;

export type UnparenthesizedPipeBodyTypes = GetSetMemberType<
typeof UnparenthesizedPipeBodyDescriptions
Expand Down
18 changes: 10 additions & 8 deletions packages/babel-traverse/src/path/family.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,9 +335,10 @@ type MaybeToIndex<T extends string> = T extends `${bigint}` ? number : T;
type Pattern<Obj extends string, Prop extends string> = `${Obj}.${Prop}`;

// split "body.body.1" to ["body", "body", 1]
type Split<P extends string> = P extends Pattern<infer O, infer U>
? [MaybeToIndex<O>, ...Split<U>]
: [MaybeToIndex<P>];
type Split<P extends string> =
P extends Pattern<infer O, infer U>
? [MaybeToIndex<O>, ...Split<U>]
: [MaybeToIndex<P>];

// get all K with Node[K] is t.Node | t.Node[]
type NodeKeyOf<Node extends t.Node | t.Node[]> = keyof Pick<
Expand All @@ -361,11 +362,12 @@ type Trav<
: never
: never;

type ToNodePath<T> = T extends Array<t.Node | null | undefined>
? Array<NodePath<T[number]>>
: T extends t.Node | null | undefined
? NodePath<T>
: never;
type ToNodePath<T> =
T extends Array<t.Node | null | undefined>
? Array<NodePath<T[number]>>
: T extends t.Node | null | undefined
? NodePath<T>
: never;

function get<T extends t.Node, K extends keyof T>(
this: NodePath<T>,
Expand Down

0 comments on commit fc0d5ad

Please sign in to comment.