Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
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
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,42 @@ | ||
import type { TypeScriptESLintRules } from '@typescript-eslint/eslint-plugin/use-at-your-own-risk/rules'; | ||
import { fetch } from 'cross-fetch'; | ||
import { markdownTable } from 'markdown-table'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I don't remember why we kept this as a dynamic import 🤔 🤷 | ||
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(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)); | ||
// 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'); | ||
console.log(`## Table Key | ||
<table> | ||
<thead> | ||
@@ -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(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!; | ||
return [ | ||
`[\`${ruleName}\`](https://typescript-eslint.io/rules/${ruleName})`, | ||
newRuleNames.has(ruleName) ? '🆕' : deprecated ? '💀' : '', | ||
requiresTypeChecking ? '💭' : '', | ||
extendsBaseRule ? '🧱' : '', | ||
recommended === 'recommended' ? '🟩' : '', | ||
recommended === 'strict' ? '🔵' : '', | ||
recommended === 'stylistic' ? '🔸' : '', | ||
]; | ||
}), | ||
]), | ||
); |
Uh oh!
There was an error while loading.Please reload this page.