From 36fd35d9bbbaec43dd911e06bd83625cd1650fb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 29 Apr 2024 15:02:16 +0800 Subject: [PATCH] feat: no-deprecated-api support removed api (#240) * feat: no-deprecated-api support removed api * Update lib/rules/no-deprecated-api.js Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com> * chore: fix typings --------- Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com> --- lib/rules/no-deprecated-api.js | 26 ++++++++++++++------------ lib/unsupported-features/types.js | 5 +++-- tests/lib/rules/no-deprecated-api.js | 11 ++++++++++- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/lib/rules/no-deprecated-api.js b/lib/rules/no-deprecated-api.js index ef7e90a5..32efff22 100644 --- a/lib/rules/no-deprecated-api.js +++ b/lib/rules/no-deprecated-api.js @@ -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 @@ -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: { @@ -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) { @@ -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} */ ( node.loc ), - messageId: "deprecated", - data: { - name, - version: info.since, - replace: toReplaceMessage(info.replacedBy, version), - }, + messageId, + data, }) } diff --git a/lib/unsupported-features/types.js b/lib/unsupported-features/types.js index faae70ce..593f8ee4 100644 --- a/lib/unsupported-features/types.js +++ b/lib/unsupported-features/types.js @@ -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} DeprecatedInfoTraceMap */ diff --git a/tests/lib/rules/no-deprecated-api.js b/tests/lib/rules/no-deprecated-api.js index 34471a9d..cead2680 100644 --- a/tests/lib/rules/no-deprecated-api.js +++ b/tests/lib/rules/no-deprecated-api.js @@ -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;",