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: no-deprecated-api support removed api #240

Merged
merged 3 commits into from
Apr 29, 2024
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
26 changes: 14 additions & 12 deletions lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ const getSemverRange = require("../util/get-semver-range")
const extendTrackmapWithNodePrefix = require("../util/extend-trackmap-with-node-prefix")
const unprefixNodeColon = require("../util/unprefix-node-colon")

/**
* @typedef DeprecatedInfo
* @property {string} since
* @property {string|{ name: string, supported: string }[]|null} replacedBy
*/
/** @typedef {import('../unsupported-features/types.js').DeprecatedInfo} DeprecatedInfo */
/**
* @typedef ParsedOptions
* @property {import('semver').Range} version
Expand Down Expand Up @@ -626,7 +622,7 @@ const globals = {
},
Intl: {
v8BreakIterator: {
[READ]: { since: "7.0.0", replacedBy: null },
[READ]: { since: "7.0.0", replacedBy: null, removed: "9.0.0" },
},
},
require: {
Expand Down Expand Up @@ -745,6 +741,8 @@ module.exports = {
messages: {
deprecated:
"{{name}} was deprecated since v{{version}}{{replace}}.",
removed:
"{{name}} was deprecated since v{{version}}, and removed in v{{removed}}.",
Copy link

Choose a reason for hiding this comment

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

It could be worth including replace here still

Copy link
Author

Choose a reason for hiding this comment

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

yes, we can add it in another PR.

},
},
create(context) {
Expand All @@ -760,17 +758,21 @@ module.exports = {
* @returns {void}
*/
function reportItem(node, name, info) {
const messageId = info.removed ? "removed" : "deprecated"
const data = {
name,
version: info.since,
removed: info.removed || "",
replace: toReplaceMessage(info.replacedBy, version),
}

context.report({
node,
loc: /** @type {NonNullable<import('estree').Node["loc"]>} */ (
node.loc
),
messageId: "deprecated",
data: {
name,
version: info.since,
replace: toReplaceMessage(info.replacedBy, version),
},
messageId,
data,
})
}

Expand Down
5 changes: 3 additions & 2 deletions lib/unsupported-features/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

/**
* @typedef DeprecatedInfo
* @property {string} since
* @property {string|{ name: string, supported: string }[]|null} replacedBy
* @property {string} since the version when the API was deprecated.
* @property {string|{ name: string, supported: string }[]|null} replacedBy the text of substitute way.
* @property {string} [removed] the version when the API was removed.
*/

/** @typedef {import('@eslint-community/eslint-utils').TraceMap<DeprecatedInfo>} DeprecatedInfoTraceMap */
Expand Down
11 changes: 10 additions & 1 deletion tests/lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,16 @@ ruleTester.run("no-deprecated-api", rule, {
{
code: "Intl.v8BreakIterator;",
options: [{ version: "7.0.0" }],
errors: ["'Intl.v8BreakIterator' was deprecated since v7.0.0."],
errors: [
{
messageId: "removed",
data: {
name: "'Intl.v8BreakIterator'",
version: "7.0.0",
removed: "9.0.0",
},
},
],
},
{
code: "require.extensions;",
Expand Down