Skip to content

Commit

Permalink
feat: no-deprecated-api support removed api
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed Apr 11, 2024
1 parent 539da1e commit fa74be9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
25 changes: 16 additions & 9 deletions lib/rules/no-deprecated-api.js
Expand Up @@ -18,8 +18,9 @@ const unprefixNodeColon = require("../util/unprefix-node-colon")

/**
* @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 ParsedOptions
Expand Down Expand Up @@ -626,7 +627,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 +746,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 +763,21 @@ module.exports = {
* @returns {void}
*/
function reportItem(node, name, info) {
const messageId = info.removed ? "removed" : "deprecated"
const data = {
name,
version: info.since,
replace: toReplaceMessage(info.replacedBy, version),
}
if (info.removed) Object.assign(data, { removed: info.removed })

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
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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -20,7 +20,7 @@
"enhanced-resolve": "^5.15.0",
"eslint-plugin-es-x": "^7.5.0",
"get-tsconfig": "^4.7.0",
"globals": "^14.0.0",
"globals": "^15.0.0",
"ignore": "^5.2.4",
"minimatch": "^9.0.0",
"semver": "^7.5.3"
Expand Down
11 changes: 10 additions & 1 deletion tests/lib/rules/no-deprecated-api.js
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 fa74be9

Please sign in to comment.