Skip to content

Commit 99dcba5

Browse files
authored
chore: enable some ts-eslint rules (#17592)
* remove ban-types The ban-types rule has been removed in ts-eslint v8. * chore: enable consistent-generic-constructors * chore: enable consistent-indexed-object-style rule * chore: enable array-type * update stringifyValidator script for array-types * chore: remove sort-type-constituents This rule has been deprecated in favor of the perfectionist/sort-intersection-types and perfectionist/sort-union-types rules. Since we have installed perfectionist, removing this rule becomes no-op. * chore: enable no-unsafe-declaration-merging
1 parent 4251ce3 commit 99dcba5

143 files changed

Lines changed: 694 additions & 681 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Gulpfile.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function generateStandalone() {
192192
${imports}
193193
export const ${exportDecls.slice(0, -1)};
194194
export {${exportsList}};
195-
export const all: { [k: string]: any } = {${allList}};
195+
export const all: Record<string, any> = {${allList}};
196196
${extraCode}`;
197197
file.path = "plugins.ts";
198198
file.contents = Buffer.from(

eslint.config.mts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,6 @@ export default defineConfig([
196196
"@typescript-eslint/require-await": "error",
197197

198198
// Todo: Investigate, for each of these, whether we want them
199-
"@typescript-eslint/array-type": "off",
200-
"@typescript-eslint/ban-types": "off",
201-
"@typescript-eslint/consistent-generic-constructors": "off",
202-
"@typescript-eslint/consistent-indexed-object-style": "off",
203199
"@typescript-eslint/consistent-type-definitions": "off",
204200
"@typescript-eslint/no-base-to-string": "off",
205201
"@typescript-eslint/no-duplicate-type-constituents": "off",
@@ -209,12 +205,10 @@ export default defineConfig([
209205
"@typescript-eslint/no-this-alias": "off",
210206
"@typescript-eslint/no-unsafe-assignment": "off",
211207
"@typescript-eslint/no-unsafe-call": "off",
212-
"@typescript-eslint/no-unsafe-declaration-merging": "off",
213208
"@typescript-eslint/no-unsafe-member-access": "off",
214209
"@typescript-eslint/prefer-for-of": "off",
215210
"@typescript-eslint/prefer-nullish-coalescing": "off",
216211
"@typescript-eslint/restrict-template-expressions": "off",
217-
"@typescript-eslint/sort-type-constituents": "off",
218212
"@typescript-eslint/unbound-method": "off",
219213
"prefer-rest-params": "off",
220214

packages/babel-cli/src/babel-external-helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const program = process.env.BABEL_8_BREAKING
55
? commander.program
66
: commander.default.program;
77

8-
function collect(value: unknown, previousValue: Array<string>): Array<string> {
8+
function collect(value: unknown, previousValue: string[]): string[] {
99
// If the user passed the option with no value, like "babel-external-helpers --whitelist", do nothing.
1010
if (typeof value !== "string") return previousValue;
1111

packages/babel-cli/src/babel/dir.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ export default async function ({
192192
} else {
193193
// A map from absolute compiled file path to its base, from which
194194
// the output destination will be determined
195-
const filenameToBaseMap: Map<string, string> = new Map(
195+
const filenameToBaseMap = new Map<string, string>(
196196
filenames.map(filename => {
197197
const absoluteFilename = path.resolve(filename);
198198
return [absoluteFilename, path.dirname(filename)];
199199
}),
200200
);
201201

202-
const absoluteFilenames: Map<string, string> = new Map(
202+
const absoluteFilenames = new Map<string, string>(
203203
filenames.map(filename => {
204204
const absoluteFilename = path.resolve(filename);
205205
return [absoluteFilename, filename];

packages/babel-cli/src/babel/file.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export default async function ({
2626
cliOptions,
2727
babelOptions,
2828
}: CmdOptions): Promise<void> {
29-
function buildResult(fileResults: Array<FileResult>): CompilationOutput {
29+
function buildResult(fileResults: FileResult[]): CompilationOutput {
3030
const mapSections: SectionedSourceMap["sections"] = [];
3131

3232
let code = "";
@@ -91,7 +91,7 @@ export default async function ({
9191
return count;
9292
}
9393

94-
function output(fileResults: Array<FileResult>): void {
94+
function output(fileResults: FileResult[]): void {
9595
const result = buildResult(fileResults);
9696

9797
if (cliOptions.outFile) {
@@ -150,7 +150,7 @@ export default async function ({
150150
output([res]);
151151
}
152152

153-
async function walk(filenames: Array<string>): Promise<void> {
153+
async function walk(filenames: string[]): Promise<void> {
154154
const _filenames: string[] = [];
155155

156156
filenames.forEach(function (filename) {
@@ -207,7 +207,7 @@ export default async function ({
207207
output(results);
208208
}
209209

210-
async function files(filenames: Array<string>): Promise<void> {
210+
async function files(filenames: string[]): Promise<void> {
211211
if (cliOptions.watch) {
212212
watcher.enable({ enableGlobbing: false });
213213
}

packages/babel-cli/src/babel/options.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export type CmdOptions = {
208208
};
209209
};
210210

211-
export default function parseArgv(args: Array<string>): CmdOptions | null {
211+
export default function parseArgv(args: string[]): CmdOptions | null {
212212
//
213213
program.parse(args);
214214

@@ -333,9 +333,9 @@ export default function parseArgv(args: Array<string>): CmdOptions | null {
333333
// new options for @babel/core, we'll potentially get option validation errors from
334334
// @babel/core. To avoid that, we delete undefined options, so @babel/core will only
335335
// give the error if users actually pass an unsupported CLI option.
336-
for (const key of Object.keys(babelOptions) as Array<
337-
keyof typeof babelOptions
338-
>) {
336+
for (const key of Object.keys(
337+
babelOptions,
338+
) as (keyof typeof babelOptions)[]) {
339339
if (babelOptions[key] === undefined) {
340340
delete babelOptions[key];
341341
}
@@ -380,7 +380,7 @@ function booleanify(val: string): boolean | string {
380380
return val;
381381
}
382382

383-
function collect(value: unknown, previousValue: Array<string>): Array<string> {
383+
function collect(value: unknown, previousValue: string[]): string[] {
384384
// If the user passed the option with no value, like "babel file.js --presets", do nothing.
385385
if (typeof value !== "string") return previousValue;
386386

packages/babel-cli/src/babel/util.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export function readdir(
2525
dirname: string,
2626
includeDotfiles: boolean,
2727
filter?: ReaddirFilter,
28-
): Array<string> {
28+
): string[] {
2929
if (process.env.BABEL_8_BREAKING) {
3030
return (
3131
fs
@@ -68,8 +68,8 @@ export function readdir(
6868
export function readdirForCompilable(
6969
dirname: string,
7070
includeDotfiles: boolean,
71-
altExts?: Array<string>,
72-
): Array<string> {
71+
altExts?: string[],
72+
): string[] {
7373
return readdir(dirname, includeDotfiles, function (filename) {
7474
return isCompilableExtension(filename, altExts);
7575
});

packages/babel-code-frame/src/defs.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ export type InternalTokenType =
2424

2525
type UITokens = "gutter" | "marker" | "message";
2626

27-
export type Defs = {
28-
[_ in InternalTokenType | UITokens | "reset"]: Formatter;
29-
};
27+
export type Defs = Record<InternalTokenType | UITokens | "reset", Formatter>;
3028

3129
const compose: <T, U, V>(f: (gv: U) => V, g: (v: T) => U) => (v: T) => V =
3230
(f, g) => v =>

packages/babel-code-frame/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type MarkerLines = Record<number, true | [number, number]>;
5151

5252
function getMarkerLines(
5353
loc: NodeLocation,
54-
source: Array<string>,
54+
source: string[],
5555
opts: Options,
5656
): {
5757
start: number;

packages/babel-core/src/config/cache-contexts.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export type FullPreset = {
1010
targets: TargetsListOrObject;
1111
} & ConfigContext;
1212
export type FullPlugin = {
13-
assumptions: { [name: string]: boolean };
13+
assumptions: Record<string, boolean>;
1414
} & FullPreset;
1515

1616
// Context not including filename since it is used in places that cannot
@@ -23,7 +23,5 @@ export type SimplePreset = {
2323
targets: TargetsListOrObject;
2424
} & SimpleConfig;
2525
export type SimplePlugin = {
26-
assumptions: {
27-
[name: string]: boolean;
28-
};
26+
assumptions: Record<string, boolean>;
2927
} & SimplePreset;

0 commit comments

Comments
 (0)