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(website): auto-inject ban-types default options#7714
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
d6054faf3b9cf20ce58a03427afbFile 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 |
|---|---|---|
| @@ -299,6 +299,33 @@ export const generatedRuleDocs: Plugin = () => { | ||
| } | ||
| } | ||
| // Insert default rule options for ban-types | ||
| if (file.stem === 'ban-types') { | ||
Member 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 do dislike having such rule-specific things in this already kind of big file... what do you think about having an mdx component like MemberAuthor 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. We already have file-specific handling for this page. This cannot be an MDX component because it has to work server-side and get statically injected instead of dynamically rendered. Member 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. Blurgh, I keep forgetting these things. MDX components don't work server-side? Is this mentioned in docs / one of the things blocked by MDX v2? (I searched and can't find it) MemberAuthor 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. MDX components are basically React components. They can get server-rendered (through the same machinery that renders the rest of the page to HTML) but they can't access server data like files. | ||
| const placeToInsert = children.findIndex( | ||
| (node: unist.Node) => | ||
| node.type === 'comment' && | ||
| (node as unist.Literal<string>).value.trim() === | ||
| 'Inject default options', | ||
| ); | ||
| if (placeToInsert === -1) { | ||
| throw new Error('Could not find default injection site in ban-types'); | ||
| } | ||
| const defaultOptions = fs | ||
| .readFileSync( | ||
| path.join(eslintPluginDirectory, 'src/rules/ban-types.ts'), | ||
| 'utf8', | ||
| ) | ||
| .match(/^const defaultTypes.+?^\};$/msu)?.[0]; | ||
| if (!defaultOptions) { | ||
| throw new Error('Could not find default options for ban-types'); | ||
| } | ||
| children.splice(placeToInsert, 1, { | ||
| lang: 'ts', | ||
| type: 'code', | ||
| value: defaultOptions, | ||
| } as mdast.Code); | ||
| } | ||
| // 5. Add a link to view the rule's source and test code | ||
| children.push( | ||
| { | ||