Skip to content

Commit fc0d5ad

Browse files
authored
Update typescript and lint tools (#16351)
1 parent 91d2158 commit fc0d5ad

File tree

7 files changed

+759
-655
lines changed

7 files changed

+759
-655
lines changed

eslint.config.js

Lines changed: 83 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// @ts-check
12
"use strict";
23

34
const configInternal = require("@babel/eslint-config-internal");
@@ -6,8 +7,7 @@ const pluginN = require("eslint-plugin-n");
67
const pluginPrettier = require("eslint-plugin-prettier");
78
const pluginBabelDevelopment = require("@babel/eslint-plugin-development");
89
const pluginBabelDevelopmentInternal = require("@babel/eslint-plugin-development-internal");
9-
const pluginTypeScriptESLint = require("@typescript-eslint/eslint-plugin");
10-
const parserTypeScriptESLint = require("@typescript-eslint/parser");
10+
const typescriptEslint = require("typescript-eslint");
1111

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

@@ -75,97 +75,92 @@ module.exports = [
7575
"import/no-extraneous-dependencies": "error",
7676
},
7777
},
78-
...compat
79-
.extends(
80-
"plugin:@typescript-eslint/recommended-type-checked",
81-
"plugin:@typescript-eslint/stylistic-type-checked"
82-
)
83-
.map(config => {
84-
return {
85-
...config,
86-
files: ["**/*.{ts,cts}"],
87-
languageOptions: {
88-
parser: parserTypeScriptESLint,
89-
parserOptions: {
90-
allowAutomaticSingleRunInference: true,
91-
EXPERIMENTAL_useProjectService: true,
78+
...typescriptEslint.config({
79+
files: ["**/*.{ts,cts}"],
80+
extends: [
81+
...typescriptEslint.configs.recommendedTypeChecked,
82+
...typescriptEslint.configs.stylisticTypeChecked,
83+
],
84+
languageOptions: {
85+
parser: typescriptEslint.parser,
86+
parserOptions: {
87+
allowAutomaticSingleRunInference: true,
88+
EXPERIMENTAL_useProjectService: true,
89+
},
90+
},
91+
plugins: {
92+
"@typescript-eslint": typescriptEslint.plugin,
93+
},
94+
rules: {
95+
"no-unused-vars": "off",
96+
"@typescript-eslint/no-unused-vars": "error",
97+
"no-dupe-class-members": "off",
98+
"@typescript-eslint/no-dupe-class-members": "error",
99+
"no-undef": "off",
100+
"no-redeclare": "off",
101+
"@typescript-eslint/ban-ts-comment": [
102+
"error",
103+
{
104+
"ts-ignore": {
105+
descriptionFormat: "^\\(Babel 7 vs Babel 8\\) .+$",
92106
},
93107
},
94-
plugins: {
95-
"@typescript-eslint": pluginTypeScriptESLint,
108+
],
109+
"@typescript-eslint/consistent-type-imports": [
110+
"error",
111+
{ disallowTypeAnnotations: false },
112+
],
113+
"@typescript-eslint/no-use-before-define": [
114+
"error",
115+
{
116+
functions: false,
117+
classes: false,
118+
allowNamedExports: true,
96119
},
97-
rules: {
98-
...config.rules,
99-
"no-unused-vars": "off",
100-
"@typescript-eslint/no-unused-vars": "error",
101-
"no-dupe-class-members": "off",
102-
"@typescript-eslint/no-dupe-class-members": "error",
103-
"no-undef": "off",
104-
"no-redeclare": "off",
105-
"@typescript-eslint/ban-ts-comment": [
106-
"error",
107-
{
108-
"ts-ignore": {
109-
descriptionFormat: "^\\(Babel 7 vs Babel 8\\) .+$",
110-
},
111-
},
112-
],
113-
"@typescript-eslint/consistent-type-imports": [
114-
"error",
115-
{ disallowTypeAnnotations: false },
116-
],
117-
"@typescript-eslint/no-use-before-define": [
118-
"error",
119-
{
120-
functions: false,
121-
classes: false,
122-
allowNamedExports: true,
123-
},
124-
],
125-
"@typescript-eslint/no-confusing-void-expression": [
126-
"error",
127-
{ ignoreArrowShorthand: true },
128-
],
129-
"@typescript-eslint/no-import-type-side-effects": "error",
120+
],
121+
"@typescript-eslint/no-confusing-void-expression": [
122+
"error",
123+
{ ignoreArrowShorthand: true },
124+
],
125+
"@typescript-eslint/no-import-type-side-effects": "error",
130126

131-
// Todo: Investigate, for each of these, whether we want them
132-
"@typescript-eslint/array-type": "off",
133-
"@typescript-eslint/ban-types": "off",
134-
"@typescript-eslint/consistent-generic-constructors": "off",
135-
"@typescript-eslint/consistent-indexed-object-style": "off",
136-
"@typescript-eslint/consistent-type-definitions": "off",
137-
"@typescript-eslint/dot-notation": "off",
138-
"@typescript-eslint/no-base-to-string": "off",
139-
"@typescript-eslint/no-duplicate-type-constituents": "off",
140-
"@typescript-eslint/no-empty-function": "off",
141-
"@typescript-eslint/no-empty-interface": "off",
142-
"@typescript-eslint/no-explicit-any": "off",
143-
"@typescript-eslint/no-misused-promises": "off",
144-
"@typescript-eslint/no-namespace": "off",
145-
"@typescript-eslint/no-this-alias": "off",
146-
"@typescript-eslint/no-unsafe-assignment": "off",
147-
"@typescript-eslint/no-unsafe-call": "off",
148-
"@typescript-eslint/no-unsafe-declaration-merging": "off",
149-
"@typescript-eslint/no-unsafe-member-access": "off",
150-
"@typescript-eslint/no-var-requires": "off",
151-
"@typescript-eslint/prefer-for-of": "off",
152-
"@typescript-eslint/prefer-function-type": "off",
153-
"@typescript-eslint/prefer-nullish-coalescing": "off",
154-
"@typescript-eslint/prefer-string-starts-ends-with": "off",
155-
"@typescript-eslint/require-await": "off",
156-
"@typescript-eslint/restrict-template-expressions": "off",
157-
"@typescript-eslint/sort-type-constituents": "off",
158-
"@typescript-eslint/triple-slash-reference": "off",
159-
"@typescript-eslint/unbound-method": "off",
160-
"prefer-rest-params": "off",
127+
// Todo: Investigate, for each of these, whether we want them
128+
"@typescript-eslint/array-type": "off",
129+
"@typescript-eslint/ban-types": "off",
130+
"@typescript-eslint/consistent-generic-constructors": "off",
131+
"@typescript-eslint/consistent-indexed-object-style": "off",
132+
"@typescript-eslint/consistent-type-definitions": "off",
133+
"@typescript-eslint/dot-notation": "off",
134+
"@typescript-eslint/no-base-to-string": "off",
135+
"@typescript-eslint/no-duplicate-type-constituents": "off",
136+
"@typescript-eslint/no-empty-function": "off",
137+
"@typescript-eslint/no-empty-interface": "off",
138+
"@typescript-eslint/no-explicit-any": "off",
139+
"@typescript-eslint/no-misused-promises": "off",
140+
"@typescript-eslint/no-namespace": "off",
141+
"@typescript-eslint/no-this-alias": "off",
142+
"@typescript-eslint/no-unsafe-assignment": "off",
143+
"@typescript-eslint/no-unsafe-call": "off",
144+
"@typescript-eslint/no-unsafe-declaration-merging": "off",
145+
"@typescript-eslint/no-unsafe-member-access": "off",
146+
"@typescript-eslint/no-var-requires": "off",
147+
"@typescript-eslint/prefer-for-of": "off",
148+
"@typescript-eslint/prefer-function-type": "off",
149+
"@typescript-eslint/prefer-nullish-coalescing": "off",
150+
"@typescript-eslint/prefer-string-starts-ends-with": "off",
151+
"@typescript-eslint/require-await": "off",
152+
"@typescript-eslint/restrict-template-expressions": "off",
153+
"@typescript-eslint/sort-type-constituents": "off",
154+
"@typescript-eslint/triple-slash-reference": "off",
155+
"@typescript-eslint/unbound-method": "off",
156+
"prefer-rest-params": "off",
161157

162-
// https://github.com/typescript-eslint/typescript-eslint/issues/5014
163-
"@typescript-eslint/no-inferrable-types": "off",
164-
"@typescript-eslint/no-unsafe-argument": "off",
165-
"@typescript-eslint/no-unsafe-return": "off",
166-
},
167-
};
168-
}),
158+
// https://github.com/typescript-eslint/typescript-eslint/issues/5014
159+
"@typescript-eslint/no-inferrable-types": "off",
160+
"@typescript-eslint/no-unsafe-argument": "off",
161+
"@typescript-eslint/no-unsafe-return": "off",
162+
},
163+
}),
169164
{
170165
files: sourceFiles("js,ts,cjs,mjs"),
171166
languageOptions: {

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,19 @@
4646
"@rollup/plugin-terser": "^0.4.4",
4747
"@types/jest": "^29.5.11",
4848
"@types/node": "^20.11.5",
49-
"@typescript-eslint/eslint-plugin": "^6.15.0",
50-
"@typescript-eslint/parser": "^6.15.0",
5149
"@yarnpkg/types": "^4.0.0",
5250
"babel-plugin-transform-charcodes": "^0.2.0",
5351
"c8": "^8.0.1",
5452
"chalk": "^5.3.0",
5553
"charcodes": "^0.2.0",
5654
"core-js": "^3.31.1",
57-
"eslint": "^8.56.0",
55+
"eslint": "^8.57.0",
5856
"eslint-formatter-codeframe": "^7.32.1",
5957
"eslint-import-resolver-node": "^0.3.9",
60-
"eslint-plugin-import": "^2.26.0",
61-
"eslint-plugin-jest": "^27.6.0",
62-
"eslint-plugin-n": "^16.5.0",
63-
"eslint-plugin-prettier": "^5.1.0",
58+
"eslint-plugin-import": "^2.29.1",
59+
"eslint-plugin-jest": "^27.9.0",
60+
"eslint-plugin-n": "^16.6.2",
61+
"eslint-plugin-prettier": "^5.1.3",
6462
"glob": "^10.3.10",
6563
"gulp": "^4.0.2",
6664
"gulp-filter": "^7.0.0",
@@ -73,7 +71,7 @@
7371
"jest-worker": "^30.0.0-alpha.2",
7472
"lint-staged": "^15.2.0",
7573
"mergeiterator": "^1.4.4",
76-
"prettier": "^3.1.1",
74+
"prettier": "^3.2.5",
7775
"rollup": "^4.9.1",
7876
"rollup-plugin-dts": "^6.1.0",
7977
"rollup-plugin-dts-5": "npm:rollup-plugin-dts@^5.3.1",
@@ -82,7 +80,8 @@
8280
"shelljs": "^0.8.5",
8381
"test262-stream": "^1.4.0",
8482
"through2": "^4.0.0",
85-
"typescript": "5.4.0-dev.20240125"
83+
"typescript": "^5.4.2",
84+
"typescript-eslint": "^7.2.0"
8685
},
8786
"workspaces": [
8887
"codemods/*",

packages/babel-helper-import-to-platform-api/src/platforms-support.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface Support {
4141

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

4646
const { node: nodeTarget, ...webTargets } = targets;
4747
const emptyNodeTarget = nodeTarget == null;

packages/babel-helper-string-parser/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ function readEscapedChar(
227227
default:
228228
if (ch >= charCodes.digit0 && ch <= charCodes.digit7) {
229229
const startPos = pos - 1;
230-
const match = input.slice(startPos, pos + 2).match(/^[0-7]+/)!;
230+
const match = input.slice(startPos, pos + 2).match(/^[0-7]+/);
231231

232232
let octalStr = match[0];
233233

packages/babel-parser/src/parse-error/pipeline-operator-errors.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export const UnparenthesizedPipeBodyDescriptions = new Set([
88
"YieldExpression",
99
] as const);
1010

11-
type GetSetMemberType<T extends Set<any>> = T extends Set<infer M>
12-
? M
13-
: unknown;
11+
type GetSetMemberType<T extends Set<any>> =
12+
T extends Set<infer M> ? M : unknown;
1413

1514
export type UnparenthesizedPipeBodyTypes = GetSetMemberType<
1615
typeof UnparenthesizedPipeBodyDescriptions

packages/babel-traverse/src/path/family.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,10 @@ type MaybeToIndex<T extends string> = T extends `${bigint}` ? number : T;
335335
type Pattern<Obj extends string, Prop extends string> = `${Obj}.${Prop}`;
336336

337337
// split "body.body.1" to ["body", "body", 1]
338-
type Split<P extends string> = P extends Pattern<infer O, infer U>
339-
? [MaybeToIndex<O>, ...Split<U>]
340-
: [MaybeToIndex<P>];
338+
type Split<P extends string> =
339+
P extends Pattern<infer O, infer U>
340+
? [MaybeToIndex<O>, ...Split<U>]
341+
: [MaybeToIndex<P>];
341342

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

364-
type ToNodePath<T> = T extends Array<t.Node | null | undefined>
365-
? Array<NodePath<T[number]>>
366-
: T extends t.Node | null | undefined
367-
? NodePath<T>
368-
: never;
365+
type ToNodePath<T> =
366+
T extends Array<t.Node | null | undefined>
367+
? Array<NodePath<T[number]>>
368+
: T extends t.Node | null | undefined
369+
? NodePath<T>
370+
: never;
369371

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

0 commit comments

Comments
 (0)