Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: use TLA in ESM scripts rather than async main().catch()#11218

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 49 additions & 69 deletionspackages/eslint-plugin/tools/generate-breaking-changes.mts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,42 @@
import type {
ESLintPluginRuleModule,
TypeScriptESLintRules,
} from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules';
import type { TypeScriptESLintRules } from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules';

import { fetch } from 'cross-fetch';
// markdown-table is ESM, hence this file needs to be `.mts`
import { markdownTable } from 'markdown-table';

async function main(): Promise<void> {
const rulesImport = await import('../src/rules/index.js');
Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I also took the liberty of turning this into a static import since... it seems like we can just turn it into a static import and get better typing? But I can revert that if that's wrong.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I don't remember why we kept this as a dynamic import 🤔 🤷

/*
weird TS resolution which adds an additional default layer in the type like:
{ default: { default: Rules }}
instead of just
{ default: Rules }
*/
const rules = rulesImport.default as unknown as Record<
string,
ESLintPluginRuleModule
>;
import rulesImport from '../src/rules/index.js';

// Annotate which rules are new since the last version
async function getNewRulesAsOfMajorVersion(
oldVersion: string,
): Promise<Set<string>> {
// 1. Get the current list of rules (already done)
const newRuleNames = Object.keys(rules);
// Annotate which rules are new since the last version
async function getNewRulesAsOfMajorVersion(
oldVersion: string,
): Promise<Set<string>> {
// 1. Get the current list of rules (already done)
const newRuleNames = Object.keys(rulesImport);

// 2. Retrieve the old version of typescript-eslint from unpkg
const oldUrl = `https://unpkg.com/@typescript-eslint/eslint-plugin@${oldVersion}/dist/configs/all.js`;
const oldFileText = await (await fetch(oldUrl)).text();
const oldObjectText = oldFileText.substring(
oldFileText.indexOf('{'),
oldFileText.lastIndexOf('}') + 1,
);
// Normally we wouldn't condone using the 'eval' API...
// But this is an internal-only script and it's the easiest way to convert
// the JS raw text into a runtime object. 🤷
let oldRulesObject!: { rules: TypeScriptESLintRules };
eval(`oldRulesObject = ${oldObjectText}`);
const oldRuleNames = new Set(Object.keys(oldRulesObject.rules));
// 2. Retrieve the old version of typescript-eslint from unpkg
const oldUrl = `https://unpkg.com/@typescript-eslint/eslint-plugin@${oldVersion}/dist/configs/all.js`;
const oldFileText = await (await fetch(oldUrl)).text();
const oldObjectText = oldFileText.substring(
oldFileText.indexOf('{'),
oldFileText.lastIndexOf('}') + 1,
);
// Normally we wouldn't condone using the 'eval' API...
// But this is an internal-only script and it's the easiest way to convert
// the JS raw text into a runtime object. 🤷
let oldRulesObject!: { rules: TypeScriptESLintRules };
eval(`oldRulesObject = ${oldObjectText}`);
const oldRuleNames = new Set(Object.keys(oldRulesObject.rules));

// 3. Get the keys that exist in (1) (new version) and not (2) (old version)
return new Set(
newRuleNames.filter(
newRuleName => !oldRuleNames.has(`@typescript-eslint/${newRuleName}`),
),
);
}
// 3. Get the keys that exist in (1) (new version) and not (2) (old version)
return new Set(
newRuleNames.filter(
newRuleName => !oldRuleNames.has(`@typescript-eslint/${newRuleName}`),
),
);
}

const newRuleNames = await getNewRulesAsOfMajorVersion('5.0.0');
const newRuleNames = await getNewRulesAsOfMajorVersion('5.0.0');

console.log(`## Table Key
console.log(`## Table Key

<table>
<thead>
Expand DownExpand Up@@ -132,28 +117,23 @@ async function main(): Promise<void> {
> Hint: search for 🆕 to find newly added rules, and ➕ or ➖ to see config changes.
`);

console.log(
markdownTable([
['Rule', 'Status', 'TC', 'Ext', "Rec'd", 'Strict', 'Style'],
...Object.entries(rules).map(([ruleName, { meta }]) => {
const { deprecated } = meta;
const { extendsBaseRule, recommended, requiresTypeChecking } =
meta.docs;

return [
`[\`${ruleName}\`](https://typescript-eslint.io/rules/${ruleName})`,
newRuleNames.has(ruleName) ? '🆕' : deprecated ? '💀' : '',
requiresTypeChecking ? '💭' : '',
extendsBaseRule ? '🧱' : '',
recommended === 'recommended' ? '🟩' : '',
recommended === 'strict' ? '🔵' : '',
recommended === 'stylistic' ? '🔸' : '',
];
}),
]),
);
}
console.log(
markdownTable([
['Rule', 'Status', 'TC', 'Ext', "Rec'd", 'Strict', 'Style'],
...Object.entries(rulesImport).map(([ruleName, { meta }]) => {
const { deprecated } = meta;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- all of our rules have meta.docs
const { extendsBaseRule, recommended, requiresTypeChecking } = meta.docs!;

main().catch((error: unknown) => {
console.error(error);
});
return [
`[\`${ruleName}\`](https://typescript-eslint.io/rules/${ruleName})`,
newRuleNames.has(ruleName) ? '🆕' : deprecated ? '💀' : '',
requiresTypeChecking ? '💭' : '',
extendsBaseRule ? '🧱' : '',
recommended === 'recommended' ? '🟩' : '',
recommended === 'strict' ? '🔵' : '',
recommended === 'stylistic' ? '🔸' : '',
];
}),
]),
);
19 changes: 6 additions & 13 deletionspackages/types/tools/copy-ast-spec.mts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -72,18 +72,11 @@ async function copyFile(
console.log('Copied', fileName);
}

async function main(): Promise<void> {
if (process.env.SKIP_AST_SPEC_REBUILD) {
// ensure the package is built
await execAsync('yarn', ['build'], { cwd: AST_SPEC_PATH });
}

await copyFile('dist', 'ast-spec.ts', code =>
code.replaceAll('export declare enum', 'export enum'),
);
if (process.env.SKIP_AST_SPEC_REBUILD) {
// ensure the package is built
await execAsync('yarn', ['build'], { cwd: AST_SPEC_PATH });
}

main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
await copyFile('dist', 'ast-spec.ts', code =>
code.replaceAll('export declare enum', 'export enum'),
);
13 changes: 3 additions & 10 deletionspackages/website-eslint/build.mts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
/* eslint-disable no-process-exit, no-console */
/* eslint-disable no-console */

import * as esbuild from 'esbuild';
import * as fs from 'node:fs/promises';
Expand DownExpand Up@@ -170,12 +170,5 @@ async function buildPackage(name: string, file: string): Promise<void> {
}

console.time('building eslint for web');

buildPackage('index', './src/index.js')
.then(() => {
console.timeEnd('building eslint for web');
})
.catch((e: unknown) => {
console.error(String(e));
process.exit(1);
});
await buildPackage('index', './src/index.js');
console.timeEnd('building eslint for web');
39 changes: 16 additions & 23 deletionspackages/website/tools/generate-website-dts.mts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -79,29 +79,22 @@ function processFiles(text: string): string {
return result;
}

async function main(): Promise<void> {
const vendor = path.join(__dirname, '..', 'src', 'vendor');
const vendor = path.join(__dirname, '..', 'src', 'vendor');

console.log('Cleaning...');
await rimraf(vendor);
await makeDirectory(vendor);
console.log('Cleaning...');
await rimraf(vendor);
await makeDirectory(vendor);

// TS-VFS
await getFileAndStoreLocally(
'/js/sandbox/vendor/typescript-vfs.d.ts',
path.join(vendor, 'typescript-vfs.d.ts'),
processFiles,
);

// Sandbox
await getFileAndStoreLocally(
'/js/sandbox/index.d.ts',
path.join(vendor, 'sandbox.d.ts'),
processFiles,
);
}
// TS-VFS
await getFileAndStoreLocally(
'/js/sandbox/vendor/typescript-vfs.d.ts',
path.join(vendor, 'typescript-vfs.d.ts'),
processFiles,
);

main().catch((error: unknown) => {
console.error(error);
process.exitCode = 1;
});
// Sandbox
await getFileAndStoreLocally(
'/js/sandbox/index.d.ts',
path.join(vendor, 'sandbox.d.ts'),
processFiles,
);
Loading

[8]ページ先頭

©2009-2025 Movatter.jp