Skip to content

Commit 36fd35d

Browse files
aladdin-addscagood
andauthored
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 <[email protected]> * chore: fix typings --------- Co-authored-by: Sebastian Good <[email protected]>
1 parent cf576cb commit 36fd35d

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

lib/rules/no-deprecated-api.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,7 @@ const getSemverRange = require("../util/get-semver-range")
1616
const extendTrackmapWithNodePrefix = require("../util/extend-trackmap-with-node-prefix")
1717
const unprefixNodeColon = require("../util/unprefix-node-colon")
1818

19-
/**
20-
* @typedef DeprecatedInfo
21-
* @property {string} since
22-
* @property {string|{ name: string, supported: string }[]|null} replacedBy
23-
*/
19+
/** @typedef {import('../unsupported-features/types.js').DeprecatedInfo} DeprecatedInfo */
2420
/**
2521
* @typedef ParsedOptions
2622
* @property {import('semver').Range} version
@@ -626,7 +622,7 @@ const globals = {
626622
},
627623
Intl: {
628624
v8BreakIterator: {
629-
[READ]: { since: "7.0.0", replacedBy: null },
625+
[READ]: { since: "7.0.0", replacedBy: null, removed: "9.0.0" },
630626
},
631627
},
632628
require: {
@@ -745,6 +741,8 @@ module.exports = {
745741
messages: {
746742
deprecated:
747743
"{{name}} was deprecated since v{{version}}{{replace}}.",
744+
removed:
745+
"{{name}} was deprecated since v{{version}}, and removed in v{{removed}}.",
748746
},
749747
},
750748
create(context) {
@@ -760,17 +758,21 @@ module.exports = {
760758
* @returns {void}
761759
*/
762760
function reportItem(node, name, info) {
761+
const messageId = info.removed ? "removed" : "deprecated"
762+
const data = {
763+
name,
764+
version: info.since,
765+
removed: info.removed || "",
766+
replace: toReplaceMessage(info.replacedBy, version),
767+
}
768+
763769
context.report({
764770
node,
765771
loc: /** @type {NonNullable<import('estree').Node["loc"]>} */ (
766772
node.loc
767773
),
768-
messageId: "deprecated",
769-
data: {
770-
name,
771-
version: info.since,
772-
replace: toReplaceMessage(info.replacedBy, version),
773-
},
774+
messageId,
775+
data,
774776
})
775777
}
776778

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 */

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)