Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions docs/users/Shared_Configurations.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ module.exports = {
</TabItem>
</Tabs>

Some rules also enabled in `recommended` default to more strict settings in this configuration.
See [`configs/strict.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict.ts) for the exact contents of this config.

:::caution
Expand Down Expand Up @@ -208,6 +209,7 @@ module.exports = {
</TabItem>
</Tabs>

Some rules also enabled in `recommended-type-checked` default to more strict settings in this configuration.
See [`configs/strict-type-checked.ts`](https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict-type-checked.ts) for the exact contents of this config.

:::caution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,20 +113,34 @@ export async function insertNewRuleReferences(
type: 'paragraph',
} as mdast.Paragraph);
} else if (!COMPLICATED_RULE_OPTIONS.has(page.file.stem)) {
const defaults =
SPECIAL_CASE_DEFAULTS.get(page.file.stem) ??
JSON.stringify(page.rule.defaultOptions);

page.spliceChildren(
page.headingIndices.options + 1,
0,
{
children: [
{
type: 'text',
value: 'This rule accepts the following options:',
} as mdast.Text,
],
children:
typeof page.rule.meta.docs.recommended === 'object'
? [
{
type: 'text',
value:
'This rule accepts the following options, and has more strict settings in the ',
} as mdast.Text,
...linkToConfigs(
page.rule.meta.docs.requiresTypeChecking
? ['strict', 'strict-type-checked']
: ['strict'],
),
{
type: 'text',
value: ` config${page.rule.meta.docs.requiresTypeChecking ? 's' : ''}.`,
} as mdast.Text,
]
: [
{
type: 'text',
value: 'This rule accepts the following options:',
} as mdast.Text,
],
type: 'paragraph',
} as mdast.Paragraph,
{
Expand All @@ -135,7 +149,7 @@ export async function insertNewRuleReferences(
value: [
await compile(page.rule.meta.schema, prettierConfig),
await prettier.format(
`const defaultOptions: Options = ${defaults};`,
getRuleDefaultOptions(page),
await prettierConfig,
),
]
Expand All @@ -147,3 +161,46 @@ export async function insertNewRuleReferences(

return eslintrc;
}

function linkToConfigs(configs: string[]): mdast.Node[] {
const links = configs.map(
(config): mdast.Link => ({
children: [
{
type: 'inlineCode',
value: config,
} as mdast.InlineCode,
],
type: 'link',
url: `/users/configs#${config})`,
}),
);

return links.length === 1
? links
: [
links[0],
{
type: 'text',
value: ' and ',
} as mdast.Text,
links[1],
];
}

function getRuleDefaultOptions(page: RuleDocsPage): string {
const defaults =
SPECIAL_CASE_DEFAULTS.get(page.file.stem) ??
JSON.stringify(page.rule.defaultOptions);

const recommended = page.rule.meta.docs.recommended;

return typeof recommended === 'object'
? [
`const defaultOptionsRecommended: Options = ${defaults};`,
'',
'// These options are merged on top of the recommended defaults',
`const defaultOptionsStrict: Options = ${JSON.stringify(recommended.strict)};`,
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd have liked to apply the actual merging logic so folks can see what the true defaults are for strict. But that'll be a little more involved. In the interest of getting this done faster I'd rather just merge this PR ASAP. Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is good for quick fix. I'd like to see the merged config. Tho on second hand, it’s nice to see easily what are the things that changed.
So maybe this needs more thought with time? But for now this looks good to me. 👍

].join('\n')
: `const defaultOptions: Options = ${defaults};`;
}