Skip to content

Commit

Permalink
feat: no-deprecated-api support removed api (#240)
Browse files Browse the repository at this point in the history
* feat: no-deprecated-api support removed api

* Update lib/rules/no-deprecated-api.js

Co-authored-by: Sebastian Good <[email protected]>

* chore: fix typings

---------

Co-authored-by: Sebastian Good <[email protected]>
  • Loading branch information
aladdin-add and scagood authored Apr 29, 2024
1 parent cf576cb commit 36fd35d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
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}}.",
},
},
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

0 comments on commit 36fd35d

Please sign in to comment.