|
1 |
| -import type { |
2 |
| - ESLintPluginRuleModule, |
3 |
| - TypeScriptESLintRules, |
4 |
| -} from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; |
| 1 | +import type { TypeScriptESLintRules } from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; |
5 | 2 |
|
6 | 3 | import { fetch } from 'cross-fetch';
|
7 |
| -// markdown-table is ESM, hence this file needs to be `.mts` |
8 | 4 | import { markdownTable } from 'markdown-table';
|
9 | 5 |
|
10 |
| -async function main(): Promise<void> { |
11 |
| - const rulesImport = await import('../src/rules/index.js'); |
12 |
| - /* |
13 |
| - weird TS resolution which adds an additional default layer in the type like: |
14 |
| - { default: { default: Rules }} |
15 |
| - instead of just |
16 |
| - { default: Rules } |
17 |
| - */ |
18 |
| - const rules = rulesImport.default as unknown as Record< |
19 |
| - string, |
20 |
| - ESLintPluginRuleModule |
21 |
| - >; |
| 6 | +import rulesImport from '../src/rules/index.js'; |
22 | 7 |
|
23 |
| - // Annotate which rules are new since the last version |
24 |
| - async function getNewRulesAsOfMajorVersion( |
25 |
| - oldVersion: string, |
26 |
| - ): Promise<Set<string>> { |
27 |
| - // 1. Get the current list of rules (already done) |
28 |
| - const newRuleNames = Object.keys(rules); |
| 8 | +// Annotate which rules are new since the last version |
| 9 | +async function getNewRulesAsOfMajorVersion( |
| 10 | + oldVersion: string, |
| 11 | +): Promise<Set<string>> { |
| 12 | + // 1. Get the current list of rules (already done) |
| 13 | + const newRuleNames = Object.keys(rulesImport); |
29 | 14 |
|
30 |
| - // 2. Retrieve the old version of typescript-eslint from unpkg |
31 |
| - const oldUrl = `https://unpkg.com/@typescript-eslint/eslint-plugin@${oldVersion}/dist/configs/all.js`; |
32 |
| - const oldFileText = await (await fetch(oldUrl)).text(); |
33 |
| - const oldObjectText = oldFileText.substring( |
34 |
| - oldFileText.indexOf('{'), |
35 |
| - oldFileText.lastIndexOf('}') + 1, |
36 |
| - ); |
37 |
| - // Normally we wouldn't condone using the 'eval' API... |
38 |
| - // But this is an internal-only script and it's the easiest way to convert |
39 |
| - // the JS raw text into a runtime object. 🤷 |
40 |
| - let oldRulesObject!: { rules: TypeScriptESLintRules }; |
41 |
| - eval(`oldRulesObject = ${oldObjectText}`); |
42 |
| - const oldRuleNames = new Set(Object.keys(oldRulesObject.rules)); |
| 15 | + // 2. Retrieve the old version of typescript-eslint from unpkg |
| 16 | + const oldUrl = `https://unpkg.com/@typescript-eslint/eslint-plugin@${oldVersion}/dist/configs/all.js`; |
| 17 | + const oldFileText = await (await fetch(oldUrl)).text(); |
| 18 | + const oldObjectText = oldFileText.substring( |
| 19 | + oldFileText.indexOf('{'), |
| 20 | + oldFileText.lastIndexOf('}') + 1, |
| 21 | + ); |
| 22 | + // Normally we wouldn't condone using the 'eval' API... |
| 23 | + // But this is an internal-only script and it's the easiest way to convert |
| 24 | + // the JS raw text into a runtime object. 🤷 |
| 25 | + let oldRulesObject!: { rules: TypeScriptESLintRules }; |
| 26 | + eval(`oldRulesObject = ${oldObjectText}`); |
| 27 | + const oldRuleNames = new Set(Object.keys(oldRulesObject.rules)); |
43 | 28 |
|
44 |
| - // 3. Get the keys that exist in (1) (new version) and not (2) (old version) |
45 |
| - return new Set( |
46 |
| - newRuleNames.filter( |
47 |
| - newRuleName => !oldRuleNames.has(`@typescript-eslint/${newRuleName}`), |
48 |
| - ), |
49 |
| - ); |
50 |
| - } |
| 29 | + // 3. Get the keys that exist in (1) (new version) and not (2) (old version) |
| 30 | + return new Set( |
| 31 | + newRuleNames.filter( |
| 32 | + newRuleName => !oldRuleNames.has(`@typescript-eslint/${newRuleName}`), |
| 33 | + ), |
| 34 | + ); |
| 35 | +} |
51 | 36 |
|
52 |
| - const newRuleNames = await getNewRulesAsOfMajorVersion('5.0.0'); |
| 37 | +const newRuleNames = await getNewRulesAsOfMajorVersion('5.0.0'); |
53 | 38 |
|
54 |
| - console.log(`## Table Key |
| 39 | +console.log(`## Table Key |
55 | 40 |
|
56 | 41 | <table>
|
57 | 42 | <thead>
|
@@ -132,28 +117,23 @@ async function main(): Promise<void> {
|
132 | 117 | > Hint: search for 🆕 to find newly added rules, and ➕ or ➖ to see config changes.
|
133 | 118 | `);
|
134 | 119 |
|
135 |
| - console.log( |
136 |
| - markdownTable([ |
137 |
| - ['Rule', 'Status', 'TC', 'Ext', "Rec'd", 'Strict', 'Style'], |
138 |
| - ...Object.entries(rules).map(([ruleName, { meta }]) => { |
139 |
| - const { deprecated } = meta; |
140 |
| - const { extendsBaseRule, recommended, requiresTypeChecking } = |
141 |
| - meta.docs; |
142 |
| - |
143 |
| - return [ |
144 |
| - `[\`${ruleName}\`](https://typescript-eslint.io/rules/${ruleName})`, |
145 |
| - newRuleNames.has(ruleName) ? '🆕' : deprecated ? '💀' : '', |
146 |
| - requiresTypeChecking ? '💭' : '', |
147 |
| - extendsBaseRule ? '🧱' : '', |
148 |
| - recommended === 'recommended' ? '🟩' : '', |
149 |
| - recommended === 'strict' ? '🔵' : '', |
150 |
| - recommended === 'stylistic' ? '🔸' : '', |
151 |
| - ]; |
152 |
| - }), |
153 |
| - ]), |
154 |
| - ); |
155 |
| -} |
| 120 | +console.log( |
| 121 | + markdownTable([ |
| 122 | + ['Rule', 'Status', 'TC', 'Ext', "Rec'd", 'Strict', 'Style'], |
| 123 | + ...Object.entries(rulesImport).map(([ruleName, { meta }]) => { |
| 124 | + const { deprecated } = meta; |
| 125 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- all of our rules have meta.docs |
| 126 | + const { extendsBaseRule, recommended, requiresTypeChecking } = meta.docs!; |
156 | 127 |
|
157 |
| -main().catch((error: unknown) => { |
158 |
| - console.error(error); |
159 |
| -}); |
| 128 | + return [ |
| 129 | + `[\`${ruleName}\`](https://typescript-eslint.io/rules/${ruleName})`, |
| 130 | + newRuleNames.has(ruleName) ? '🆕' : deprecated ? '💀' : '', |
| 131 | + requiresTypeChecking ? '💭' : '', |
| 132 | + extendsBaseRule ? '🧱' : '', |
| 133 | + recommended === 'recommended' ? '🟩' : '', |
| 134 | + recommended === 'strict' ? '🔵' : '', |
| 135 | + recommended === 'stylistic' ? '🔸' : '', |
| 136 | + ]; |
| 137 | + }), |
| 138 | + ]), |
| 139 | +); |
0 commit comments