Skip to content

Commit

Permalink
fix: unsupported-features/node-builtins-modules version comparation (#…
Browse files Browse the repository at this point in the history
…257)

* fix: unsupported-features/node-builtins-modules

#250

* Reapply "fix: unsupported-features/node-builtins-modules range compare" (#254)

This reverts commit caecf3e.

* Update lib/util/check-unsupported-builtins.js

Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>

* chore: remove a unrelated test

---------

Co-authored-by: Sebastian Good <2230835+scagood@users.noreply.github.com>
  • Loading branch information
aladdin-add and scagood authored Apr 30, 2024
1 parent 36fd35d commit 5c67787
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/util/check-unsupported-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
*/
"use strict"

const { major, rsort } = require("semver")
const { rsort } = require("semver")
const { ReferenceTracker } = require("@eslint-community/eslint-utils")
const getConfiguredNodeVersion = require("./get-configured-node-version")
const getSemverRange = require("./get-semver-range")
const unprefixNodeColon = require("./unprefix-node-colon")
const semverRangeSubset = require("semver/ranges/subset")

/**
* Parses the options.
Expand Down Expand Up @@ -38,19 +39,14 @@ function isSupported({ supported }, configured) {

const [latest] = rsort(supported)
const range = getSemverRange(
[
...supported.map(
version => `>= ${version} < ${major(version) + 1}`
),
`> ${major(latest)}`,
].join("||")
[...supported.map(version => `^${version}`), `>= ${latest}`].join("||")
)

if (range == null) {
return false
}

return configured.intersects(range)
return semverRangeSubset(configured, range)
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tests/lib/rules/no-unsupported-features/es-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -2424,6 +2424,23 @@ runTests([
},
],
},
// https://github.com/eslint-community/eslint-plugin-n/issues/250
{
code: "function wrap() { globalThis }",
settings: {
node: { version: ">=11.9.9" },
},
errors: [
{
messageId: "not-supported-till",
data: {
name: "globalThis",
supported: "12.0.0",
version: ">=11.9.9",
},
},
],
},
],
},
])

0 comments on commit 5c67787

Please sign in to comment.