Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always display plugin prefix in deprecated rule replacement rule name #296

Merged
merged 1 commit into from Nov 27, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/examples/eslint-plugin-test/docs/rules/require-baz.md
@@ -1,6 +1,6 @@
# Require using baz (`test/require-baz`)

❌ This rule is deprecated. It was replaced by [`prefer-bar`](prefer-bar.md).
❌ This rule is deprecated. It was replaced by [`test/prefer-bar`](prefer-bar.md).

🚫 This rule is _disabled_ in the ⌨️ `typescript` config.

Expand Down
1 change: 1 addition & 0 deletions lib/rule-doc-notices.ts
Expand Up @@ -181,6 +181,7 @@ const RULE_NOTICES: {
pathRuleDoc,
urlCurrentPage,
true,
true,
urlRuleDoc
)
);
Expand Down
12 changes: 7 additions & 5 deletions lib/rule-link.ts
Expand Up @@ -68,10 +68,12 @@ export function getLinkToRule(
pathRuleDoc: string,
urlCurrentPage: string,
includeBackticks: boolean,
includePrefix: boolean,
urlRuleDoc?: string
) {
// Ignore plugin prefix if it's included in rule name.
// While we could display the prefix if we wanted, it definitely cannot be part of the link.
const ruleNameWithPluginPrefix = ruleName.startsWith(`${pluginPrefix}/`)
? ruleName
: `${pluginPrefix}/${ruleName}`;
const ruleNameWithoutPluginPrefix = ruleName.startsWith(`${pluginPrefix}/`)
? ruleName.slice(pluginPrefix.length + 1)
: ruleName;
Expand All @@ -83,7 +85,7 @@ export function getLinkToRule(
urlCurrentPage,
urlRuleDoc
);
return `[${includeBackticks ? '`' : ''}${ruleNameWithoutPluginPrefix}${
includeBackticks ? '`' : ''
}](${urlToRule})`;
return `[${includeBackticks ? '`' : ''}${
includePrefix ? ruleNameWithPluginPrefix : ruleNameWithoutPluginPrefix
}${includeBackticks ? '`' : ''}](${urlToRule})`;
}
1 change: 1 addition & 0 deletions lib/rule-list.ts
Expand Up @@ -136,6 +136,7 @@ function buildRuleRow(
pathRuleDoc,
pathRuleList,
false,
false,
urlRuleDoc
);
},
Expand Down
Expand Up @@ -18,7 +18,7 @@ exports[`generate (--url-rule-doc) basic uses the right URLs 1`] = `
exports[`generate (--url-rule-doc) basic uses the right URLs 2`] = `
"# Description for no-foo (\`test/no-foo\`)

❌ This rule is deprecated. It was replaced by [\`no-bar\`](https://example.com/rule-docs/no-bar/).
❌ This rule is deprecated. It was replaced by [\`test/no-bar\`](https://example.com/rule-docs/no-bar/).

<!-- end auto-generated rule header -->
"
Expand Down
12 changes: 6 additions & 6 deletions test/lib/generate/__snapshots__/rule-deprecation-test.ts.snap
Expand Up @@ -18,7 +18,7 @@ exports[`generate (deprecated rules) several deprecated rules updates the docume
exports[`generate (deprecated rules) several deprecated rules updates the documentation 2`] = `
"# Description (\`test/no-foo\`)

❌ This rule is deprecated. It was replaced by [\`no-bar\`](../../docs/rules/no-bar.md).
❌ This rule is deprecated. It was replaced by [\`test/no-bar\`](../../docs/rules/no-bar.md).

<!-- end auto-generated rule header -->
"
Expand Down Expand Up @@ -65,7 +65,7 @@ exports[`generate (deprecated rules) using prefix ahead of replacement rule name
exports[`generate (deprecated rules) using prefix ahead of replacement rule name uses correct replacement rule link 2`] = `
"# Description (\`test/no-foo\`)

❌ This rule is deprecated. It was replaced by [\`no-bar\`](../../docs/rules/no-bar.md).
❌ This rule is deprecated. It was replaced by [\`test/no-bar\`](../../docs/rules/no-bar.md).

<!-- end auto-generated rule header -->
"
Expand Down Expand Up @@ -94,7 +94,7 @@ exports[`generate (deprecated rules) with --path-rule-doc has the correct links,
exports[`generate (deprecated rules) with --path-rule-doc has the correct links, especially replacement rule link 2`] = `
"# Description (\`test/category/no-foo\`)

❌ This rule is deprecated. It was replaced by [\`category/no-bar\`](../../../docs/category/no-bar/README.md).
❌ This rule is deprecated. It was replaced by [\`test/category/no-bar\`](../../../docs/category/no-bar/README.md).

<!-- end auto-generated rule header -->
"
Expand All @@ -103,7 +103,7 @@ exports[`generate (deprecated rules) with --path-rule-doc has the correct links,
exports[`generate (deprecated rules) with --path-rule-doc has the correct links, especially replacement rule link 3`] = `
"# Description (\`test/category/no-bar\`)

❌ This rule is deprecated. It was replaced by [\`category/no-foo\`](../../../docs/category/no-foo/README.md).
❌ This rule is deprecated. It was replaced by [\`test/category/no-foo\`](../../../docs/category/no-foo/README.md).

<!-- end auto-generated rule header -->
"
Expand All @@ -125,7 +125,7 @@ exports[`generate (deprecated rules) with nested rule names has the correct link
exports[`generate (deprecated rules) with nested rule names has the correct links, especially replacement rule link 2`] = `
"# Description (\`test/category/no-foo\`)

❌ This rule is deprecated. It was replaced by [\`category/no-bar\`](../../../docs/rules/category/no-bar.md).
❌ This rule is deprecated. It was replaced by [\`test/category/no-bar\`](../../../docs/rules/category/no-bar.md).

<!-- end auto-generated rule header -->
"
Expand All @@ -134,7 +134,7 @@ exports[`generate (deprecated rules) with nested rule names has the correct link
exports[`generate (deprecated rules) with nested rule names has the correct links, especially replacement rule link 3`] = `
"# Description (\`test/category/no-bar\`)

❌ This rule is deprecated. It was replaced by [\`category/no-foo\`](../../../docs/rules/category/no-foo.md).
❌ This rule is deprecated. It was replaced by [\`test/category/no-foo\`](../../../docs/rules/category/no-foo.md).

<!-- end auto-generated rule header -->
"
Expand Down