Skip to content

Commit

Permalink
🐛 fix no-deprecated-api to hide unsupported alts correctly (fixes #176)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Sep 4, 2019
1 parent a0f0ee1 commit b71d483
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -662,13 +662,11 @@ function toReplaceMessage(replacedBy, version) {

if (Array.isArray(replacedBy)) {
message = replacedBy
.reduce(
(collector, { name, supported }) =>
version.intersects(getSemverRange(`>=${supported}`))
? collector.concat(name)
: collector,
[]
.filter(
({ supported }) =>
!version.intersects(getSemverRange(`<${supported}`))
)
.map(({ name }) => name)
.join(" or ")
}

Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/no-deprecated-api/gte4/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"engines": {
"node": ">=4.0.0"
}
}
14 changes: 14 additions & 0 deletions tests/lib/rules/no-deprecated-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
"use strict"

const path = require("path")
const { RuleTester } = require("eslint")
const rule = require("../../../lib/rules/no-deprecated-api")

Expand Down Expand Up @@ -986,5 +987,18 @@ ruleTester.run("no-deprecated-api", rule, {
"'Buffer()' was deprecated since v6.0.0. Use 'Buffer.alloc()' or 'Buffer.from()' instead.",
],
},

// https://github.com/mysticatea/eslint-plugin-node/issues/176
{
filename: path.resolve(
__dirname,
"../../fixtures/no-deprecated-api/gte4/test.js"
),
code: "require('assert').equal",
env: { node: true },
errors: [
"'assert.equal' was deprecated since v10.0.0. Use 'assert.strictEqual' instead.",
],
},
],
})

0 comments on commit b71d483

Please sign in to comment.