From cdcbb7ce0ff1bc6cf5f0bd10f31306b89fe1c61f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 29 Apr 2024 03:24:42 +0800 Subject: [PATCH] Reapply "fix: unsupported-features/node-builtins-modules range compare" (#254) This reverts commit caecf3ebeea5aab9edf248935250691e6065724d. --- lib/util/check-unsupported-builtins.js | 3 ++- .../no-unsupported-features/es-builtins.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/util/check-unsupported-builtins.js b/lib/util/check-unsupported-builtins.js index 2f6e5a6f..63a96d8f 100644 --- a/lib/util/check-unsupported-builtins.js +++ b/lib/util/check-unsupported-builtins.js @@ -9,6 +9,7 @@ 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. @@ -50,7 +51,7 @@ function isSupported({ supported }, configured) { 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", + }, + }, + ], + }, ], }, ])