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

feat: introduce new deprecated types for rules #19238

Merged
merged 51 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
bb8a2b2
feat: introduce new deprecated types
DMartens Dec 11, 2024
0a8be53
feat: rules use new deprecated format
DMartens Dec 11, 2024
c4d9c9b
feat: support new deprecated format in usedDeprecatedRules
DMartens Dec 11, 2024
60bc4f9
docs: document new deprecated format
DMartens Dec 11, 2024
09a07cd
fix: Use formatting rules instead of stylistic rules are being removed
DMartens Dec 20, 2024
cb8202e
fix: Clarify the replacement is from ESLint Stylistic
DMartens Dec 20, 2024
2d28ec3
docs: automatically add deprecated rules notice
DMartens Jan 18, 2025
3eb611d
docs: handle missing replacement rule for rule deprecations
DMartens Jan 18, 2025
816166e
Merge branch 'main' into deprecated-rule-metadata
DMartens Jan 18, 2025
9bcb965
docs: stop checking for manually added rule deprecation notices
DMartens Jan 18, 2025
a887786
docs: apply suggestions
DMartens Jan 18, 2025
0a0e7f5
docs: fix lint errors
DMartens Jan 18, 2025
f9726e3
docs: Clarify null for availableUntil is not the same as frozen
DMartens Jan 20, 2025
27dd0f3
fix: rule deprecation messages for node and various suggestions
DMartens Jan 24, 2025
a4ef007
fix: internal links
DMartens Jan 24, 2025
47e7445
fix: sync deprecated node rules messages and descriptions
DMartens Jan 25, 2025
a2df4e7
fix: add rule deprecation type tests
DMartens Jan 27, 2025
86158e8
fix: re-add .md file extension for rules from eslint-plugin-n
DMartens Jan 27, 2025
ad2e3e6
fix: add periods to sentence ends
DMartens Jan 28, 2025
3789bc1
fix: showing rule replacements for deprecated and removed rules in ru…
DMartens Jan 28, 2025
00418a2
fix: add urls for replacement of deprecated rules in favor of padding…
DMartens Jan 29, 2025
2119a57
fix: always provide a rule meta.deprecated.url
DMartens Jan 29, 2025
9da6e1d
fix: alias func-call-spacing as the replacement rule is renamed to ke…
DMartens Jan 29, 2025
8baace5
fix: convert callback-return and indent-legacy to new deprecated format
DMartens Jan 30, 2025
79d3579
fix: normalize deprecated rule messages
DMartens Jan 30, 2025
ac457e4
chore: fix single quotes in eslint tests
DMartens Jan 30, 2025
72e07e8
fix: use external links to rule replacements in the rule reference
DMartens Jan 31, 2025
72cdd02
fix: remove shadowing of rule in makefile
DMartens Jan 31, 2025
70439e3
fix: add external plugin reference for deprecated rules in the rule r…
DMartens Feb 11, 2025
fd5557e
fix: remove manual deprecation notice of no-new-object
DMartens Feb 11, 2025
2ae6aab
fix: cleanup rule-list macro
DMartens Feb 12, 2025
a1b4c82
fix: update rule-list documentation
DMartens Feb 13, 2025
a1ec4a6
fix: use DeprecatedInfo type from @eslint/core
DMartens Feb 13, 2025
398ccf1
Merge branch 'main' into deprecated-rule-metadata
DMartens Feb 16, 2025
aadbd4e
fix: use shorthand plugin names for usedDeprecatedRules
DMartens Feb 19, 2025
78f512e
fix: restore check for deprecated JSDoc tags for rule files
DMartens Feb 19, 2025
ad91560
fix: adjust JSDoc description and error message as README no longer c…
DMartens Feb 19, 2025
f2546ae
fix: use correct name in deprecation info for arrow-spacing
DMartens Feb 19, 2025
c2e14d3
fix: use correct name in deprecation info for multiline-comment-style
DMartens Feb 19, 2025
dd4c6b5
fix: correct package source of eslint-plugin-n in replacement infos
DMartens Feb 20, 2025
1a9732a
fix: rule docs site uses relative pages for internal rule replacements
DMartens Feb 20, 2025
c1eb5c0
fix: deprecation rule for no-buffer-constructor
DMartens Feb 21, 2025
264be63
fix: deprecation rule for no-restricted-modules
DMartens Feb 21, 2025
f1937a9
docs: Add dot at the end of a core rule replacement.
DMartens Feb 21, 2025
52e151f
fix: use relative links for replacement rules in the rule reference
DMartens Feb 21, 2025
b4a966d
fix: rule-type-list data for removed rules use new replacement format
DMartens Feb 21, 2025
fecc7f9
fix: no rendering of replacement rule lists if there are no replacements
DMartens Feb 21, 2025
3183761
fix: run pretteir on rule-type-list.json
DMartens Feb 21, 2025
3b626ae
docs: change description of `url` for deprecation meta
DMartens Feb 21, 2025
35d36d5
fix: deprecation version of no-spaced-fnc
DMartens Feb 21, 2025
ff3666f
fix: replacement rule of no-new-symbol
DMartens Feb 21, 2025
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
Prev Previous commit
Next Next commit
feat: support new deprecated format in usedDeprecatedRules
  • Loading branch information
DMartens committed Dec 11, 2024
commit c4d9c9bed49f40fab6556bdfaee8b0750925c5bf
2 changes: 1 addition & 1 deletion Makefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function generateRuleIndexPage() {
if (rule.meta.deprecated) {
ruleTypesData.deprecated.push({
name: basename,
replacedBy: rule.meta.replacedBy || [],
replacedBy: rule.meta.deprecated.replacedBy || [],
fixable: !!rule.meta.fixable,
hasSuggestions: !!rule.meta.hasSuggestions
});
Expand Down
8 changes: 7 additions & 1 deletion lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,13 @@ function getOrFindUsedDeprecatedRules(eslint, maybeFilePath) {
const meta = rule && rule.meta;

if (meta && meta.deprecated) {
retv.push({ ruleId, replacedBy: meta.replacedBy || [] });
const usesNewFormat = typeof meta.deprecated === "object";

retv.push({
ruleId,
replacedBy: usesNewFormat ? meta.deprecated.replacedBy?.map(replacement => `${replacement.plugin?.name !== void 0 ? `${replacement.plugin.name}/` : ""}${replacement.rule?.name ?? ""}`) ?? [] : meta.replacedBy || [],
Copy link
Member

Choose a reason for hiding this comment

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

I checked again the RFC and it's not indicated how normalizing rule names for usedDeprecatedRules should work in the case of external rules. With this logic, the replacement rule names would look like "@stylistic/eslint-plugin-js/semi", but the standard notation for such a rule in a configuration object is "@stylistic/js/semi". Shall we use this format instead? Or something else? @eslint/eslint-tsc

The short form of the plugin prefix can be retrieved with naming.getShorthandName like here: https://github.com/eslint/eslint/blob/e89a54a3090f3503daf5e36b02b0035c993e3fd1/lib/eslint/eslint.js#L499C25-L499C66

Copy link
Member

Choose a reason for hiding this comment

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

I think we should use the name as it would likely appear in the config, so @stylistic/js/semi would be my choice.

Copy link
Member

Choose a reason for hiding this comment

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

I'm also in favor of normalizing to @stylistic/js/semi.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should the shorthand name also be used when displaying the replacement rules in the documentation?

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a strong preference, but I think it's fine to be more descriptive in the documentation. The current format "Replaced by semi in @stylistic/eslint-plugin-js" sounds good to me.

info: usesNewFormat ? meta.deprecated : void 0
});
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion tests/bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,27 @@ describe("bin/eslint.js", () => {
usedDeprecatedRules: [
{
ruleId: "no-extra-semi",
replacedBy: []
replacedBy: ["@stylistic/eslint-plugin-js/no-extra-semi"],
info: {
message: "Stylistic rules are being moved out of ESLint core.",
url: "https://eslint.org/blog/2023/10/deprecating-formatting-rules/",
deprecatedSince: "8.53.0",
availableUntil: "10.0.0",
replacedBy: [
{
message: "Maintains now deprecated stylistic core rules",
url: "https://eslint.style/guide/migration",
plugin: {
name: "@stylistic/eslint-plugin-js",
url: "https://eslint.style/packages/js"
},
rule: {
name: "no-extra-semi",
url: "https://eslint.style/rules/js/no-extra-semi"
}
}
]
}
}
]
}
Expand Down
126 changes: 94 additions & 32 deletions tests/lib/eslint/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,8 @@ describe("ESLint", () => {
usedDeprecatedRules: [
{
ruleId: "semi",
replacedBy: []
replacedBy: ["@stylistic/eslint-plugin-js/semi"],
info: coreRules.get("semi").meta.deprecated
}
]
}
Expand Down Expand Up @@ -914,7 +915,7 @@ describe("ESLint", () => {

assert.deepStrictEqual(
result.usedDeprecatedRules,
[{ ruleId: "indent-legacy", replacedBy: ["indent"] }]
[{ ruleId: "indent-legacy", replacedBy: ["indent"], info: void 0 }]
);
});

Expand Down Expand Up @@ -996,7 +997,7 @@ describe("ESLint", () => {
flags,
cwd: getFixturePath("promise-config")
});
const results = await eslint.lintText('var foo = "bar";');
const results = await eslint.lintText("var foo = \"bar\";");

assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].messages.length, 1);
Expand Down Expand Up @@ -3164,9 +3165,23 @@ describe("ESLint", () => {
cwd: originalDir,
overrideConfigFile: true,
overrideConfig: {
plugins: {
test: {
rules: {
"deprecated-with-replacement": {
meta: { deprecated: true, replacedBy: ["replacement"] },
create: () => ({})
},
"deprecated-without-replacement": {
meta: { deprecated: true },
create: () => ({})
}
}
}
},
rules: {
"indent-legacy": 1,
"callback-return": 1
"test/deprecated-with-replacement": "error",
"test/deprecated-without-replacement": "error"
}
}
});
Expand All @@ -3175,8 +3190,8 @@ describe("ESLint", () => {
assert.deepStrictEqual(
results[0].usedDeprecatedRules,
[
{ ruleId: "indent-legacy", replacedBy: ["indent"] },
{ ruleId: "callback-return", replacedBy: [] }
{ ruleId: "test/deprecated-with-replacement", replacedBy: ["replacement"], info: void 0 },
{ ruleId: "test/deprecated-without-replacement", replacedBy: [], info: void 0 }
]
);
});
Expand Down Expand Up @@ -3205,7 +3220,42 @@ describe("ESLint", () => {

assert.deepStrictEqual(
results[0].usedDeprecatedRules,
[{ ruleId: "indent-legacy", replacedBy: ["indent"] }]
[{ ruleId: "indent-legacy", replacedBy: ["indent"], info: void 0 }]
);
});

it("should add the plugin name to the replacement if available", async () => {
const deprecated = {
message: "Deprecation",
url: "https://example.com",
replacedBy: [{ message: "Replacement", plugin: { name: "plugin" }, rule: { name: "name" } }]
};

eslint = new ESLint({
flags,
cwd: originalDir,
overrideConfigFile: true,
overrideConfig: {
plugins: {
test: {
rules: {
deprecated: {
meta: { deprecated },
create: () => ({})
}
}
}
},
rules: {
"test/deprecated": "error"
}
}
});
const results = await eslint.lintFiles(["lib/cli*.js"]);

assert.deepStrictEqual(
results[0].usedDeprecatedRules,
[{ ruleId: "test/deprecated", replacedBy: ["plugin/name"], info: deprecated }]
);
});
});
Expand Down Expand Up @@ -3288,16 +3338,19 @@ describe("ESLint", () => {
output: "true ? \"yes\" : \"no\";\n",
usedDeprecatedRules: [
{
replacedBy: [],
ruleId: "semi"
ruleId: "semi",
replacedBy: ["@stylistic/eslint-plugin-js/semi"],
info: coreRules.get("semi").meta.deprecated
},
{
replacedBy: [],
ruleId: "quotes"
ruleId: "quotes",
replacedBy: ["@stylistic/eslint-plugin-js/quotes"],
info: coreRules.get("quotes").meta.deprecated
},
{
replacedBy: [],
ruleId: "space-infix-ops"
ruleId: "space-infix-ops",
replacedBy: ["@stylistic/eslint-plugin-js/space-infix-ops"],
info: coreRules.get("space-infix-ops").meta.deprecated
}
]
},
Expand All @@ -3312,16 +3365,19 @@ describe("ESLint", () => {
fixableWarningCount: 0,
usedDeprecatedRules: [
{
replacedBy: [],
ruleId: "semi"
ruleId: "semi",
replacedBy: ["@stylistic/eslint-plugin-js/semi"],
info: coreRules.get("semi").meta.deprecated
},
{
replacedBy: [],
ruleId: "quotes"
ruleId: "quotes",
replacedBy: ["@stylistic/eslint-plugin-js/quotes"],
info: coreRules.get("quotes").meta.deprecated
},
{
replacedBy: [],
ruleId: "space-infix-ops"
ruleId: "space-infix-ops",
replacedBy: ["@stylistic/eslint-plugin-js/space-infix-ops"],
info: coreRules.get("space-infix-ops").meta.deprecated
}
]
},
Expand Down Expand Up @@ -3349,16 +3405,19 @@ describe("ESLint", () => {
output: "var msg = \"hi\";\nif (msg == \"hi\") {\n\n}\n",
usedDeprecatedRules: [
{
replacedBy: [],
ruleId: "semi"
ruleId: "semi",
replacedBy: ["@stylistic/eslint-plugin-js/semi"],
info: coreRules.get("semi").meta.deprecated
},
{
replacedBy: [],
ruleId: "quotes"
ruleId: "quotes",
replacedBy: ["@stylistic/eslint-plugin-js/quotes"],
info: coreRules.get("quotes").meta.deprecated
},
{
replacedBy: [],
ruleId: "space-infix-ops"
ruleId: "space-infix-ops",
replacedBy: ["@stylistic/eslint-plugin-js/space-infix-ops"],
info: coreRules.get("space-infix-ops").meta.deprecated
}
]
},
Expand Down Expand Up @@ -3386,16 +3445,19 @@ describe("ESLint", () => {
output: "var msg = \"hi\" + foo;\n",
usedDeprecatedRules: [
{
replacedBy: [],
ruleId: "semi"
ruleId: "semi",
replacedBy: ["@stylistic/eslint-plugin-js/semi"],
info: coreRules.get("semi").meta.deprecated
},
{
replacedBy: [],
ruleId: "quotes"
ruleId: "quotes",
replacedBy: ["@stylistic/eslint-plugin-js/quotes"],
info: coreRules.get("quotes").meta.deprecated
},
{
replacedBy: [],
ruleId: "space-infix-ops"
ruleId: "space-infix-ops",
replacedBy: ["@stylistic/eslint-plugin-js/space-infix-ops"],
info: coreRules.get("space-infix-ops").meta.deprecated
}
]
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy