Skip to content

Commit fa74be9

Browse files
committed
feat: no-deprecated-api support removed api
1 parent 539da1e commit fa74be9

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

lib/rules/no-deprecated-api.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ const unprefixNodeColon = require("../util/unprefix-node-colon")
1818

1919
/**
2020
* @typedef DeprecatedInfo
21-
* @property {string} since
22-
* @property {string|{ name: string, supported: string }[]|null} replacedBy
21+
* @property {string} since the version when the API was deprecated.
22+
* @property {string|{ name: string, supported: string }[]|null} replacedBy the text of substitute way.
23+
* @property {string} [removed] the version when the API was removed.
2324
*/
2425
/**
2526
* @typedef ParsedOptions
@@ -626,7 +627,7 @@ const globals = {
626627
},
627628
Intl: {
628629
v8BreakIterator: {
629-
[READ]: { since: "7.0.0", replacedBy: null },
630+
[READ]: { since: "7.0.0", replacedBy: null, removed: "9.0.0" },
630631
},
631632
},
632633
require: {
@@ -745,6 +746,8 @@ module.exports = {
745746
messages: {
746747
deprecated:
747748
"{{name}} was deprecated since v{{version}}{{replace}}.",
749+
removed:
750+
"{{name}} was deprecated since v{{version}}, and removed in v{{removed}}.",
748751
},
749752
},
750753
create(context) {
@@ -760,17 +763,21 @@ module.exports = {
760763
* @returns {void}
761764
*/
762765
function reportItem(node, name, info) {
766+
const messageId = info.removed ? "removed" : "deprecated"
767+
const data = {
768+
name,
769+
version: info.since,
770+
replace: toReplaceMessage(info.replacedBy, version),
771+
}
772+
if (info.removed) Object.assign(data, { removed: info.removed })
773+
763774
context.report({
764775
node,
765776
loc: /** @type {NonNullable<import('estree').Node["loc"]>} */ (
766777
node.loc
767778
),
768-
messageId: "deprecated",
769-
data: {
770-
name,
771-
version: info.since,
772-
replace: toReplaceMessage(info.replacedBy, version),
773-
},
779+
messageId,
780+
data,
774781
})
775782
}
776783

lib/unsupported-features/types.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
/**
1919
* @typedef DeprecatedInfo
20-
* @property {string} since
21-
* @property {string|{ name: string, supported: string }[]|null} replacedBy
20+
* @property {string} since the version when the API was deprecated.
21+
* @property {string|{ name: string, supported: string }[]|null} replacedBy the text of substitute way.
22+
* @property {string} [removed] the version when the API was removed.
2223
*/
2324

2425
/** @typedef {import('@eslint-community/eslint-utils').TraceMap<DeprecatedInfo>} DeprecatedInfoTraceMap */

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"enhanced-resolve": "^5.15.0",
2121
"eslint-plugin-es-x": "^7.5.0",
2222
"get-tsconfig": "^4.7.0",
23-
"globals": "^14.0.0",
23+
"globals": "^15.0.0",
2424
"ignore": "^5.2.4",
2525
"minimatch": "^9.0.0",
2626
"semver": "^7.5.3"

tests/lib/rules/no-deprecated-api.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,16 @@ ruleTester.run("no-deprecated-api", rule, {
791791
{
792792
code: "Intl.v8BreakIterator;",
793793
options: [{ version: "7.0.0" }],
794-
errors: ["'Intl.v8BreakIterator' was deprecated since v7.0.0."],
794+
errors: [
795+
{
796+
messageId: "removed",
797+
data: {
798+
name: "'Intl.v8BreakIterator'",
799+
version: "7.0.0",
800+
removed: "9.0.0",
801+
},
802+
},
803+
],
795804
},
796805
{
797806
code: "require.extensions;",

0 commit comments

Comments
 (0)