diff --git a/lib/util/check-unsupported-builtins.js b/lib/util/check-unsupported-builtins.js index db2ae46f..5d4a742e 100644 --- a/lib/util/check-unsupported-builtins.js +++ b/lib/util/check-unsupported-builtins.js @@ -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. @@ -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) } /** diff --git a/tests/lib/rules/no-unsupported-features/es-builtins.js b/tests/lib/rules/no-unsupported-features/es-builtins.js index 1ca57dd1..a78c9cce 100644 --- a/tests/lib/rules/no-unsupported-features/es-builtins.js +++ b/tests/lib/rules/no-unsupported-features/es-builtins.js @@ -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", + }, + }, + ], + }, ], }, ])