From 4fd0965a90fe12c87ff7e8f3c0cc006c1467800f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Mon, 6 May 2024 16:22:05 +0800 Subject: [PATCH] feat(import-target): Add resolution error reason --- tests/eslint-rule-tester.js | 21 +++++++++++++++++++++ tests/lib/rules/no-missing-import.js | 3 ++- tests/lib/rules/no-missing-require.js | 3 ++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/eslint-rule-tester.js b/tests/eslint-rule-tester.js index e4379ba1..9f11d22d 100644 --- a/tests/eslint-rule-tester.js +++ b/tests/eslint-rule-tester.js @@ -8,12 +8,17 @@ const { RuleTester } = require("eslint") const { FlatRuleTester } = require("eslint/use-at-your-own-risk") const globals = require("globals") const semverSatisfies = require("semver/functions/satisfies") +const os = require("os") // greater than or equal to ESLint v9 exports.gteEslintV9 = semverSatisfies(eslintVersion, ">=9", { includePrerelease: true, }) +const platform = os.platform() +exports.isCaseSensitiveFileSystem = + platform === "linux" || platform === "freebsd" || platform === "openbsd" + exports.FlatRuleTester = exports.gteEslintV9 ? RuleTester : FlatRuleTester // to support the `env:{ es6: true, node: true}` rule-tester (env has been away in flat config.) @@ -38,5 +43,21 @@ exports.RuleTester = function (config = defaultConfig) { ) const ruleTester = new exports.FlatRuleTester(config) + const $run = ruleTester.run.bind(ruleTester) + ruleTester.run = function (name, rule, tests) { + tests.valid = tests.valid.filter(shouldRun) + tests.invalid = tests.invalid.filter(shouldRun) + + $run(name, rule, tests) + } return ruleTester } + +// support skip in tests +function shouldRun(item) { + if (typeof item === "string") return true + + const skip = item.skip + delete item.skip + return skip === void 0 || skip === false +} diff --git a/tests/lib/rules/no-missing-import.js b/tests/lib/rules/no-missing-import.js index f2803b63..b4177d3f 100644 --- a/tests/lib/rules/no-missing-import.js +++ b/tests/lib/rules/no-missing-import.js @@ -6,7 +6,7 @@ const path = require("path") const { Linter } = require("eslint") -const { RuleTester } = require("#eslint-rule-tester") +const { RuleTester, isCaseSensitiveFileSystem } = require("#eslint-rule-tester") const rule = require("../../../lib/rules/no-missing-import") const DynamicImportSupported = (() => { @@ -427,6 +427,7 @@ ruleTester.run("no-missing-import", rule, { filename: fixture("test.js"), code: "import a from './A.js';", errors: cantResolve("./A.js"), + skip: !isCaseSensitiveFileSystem, }, { diff --git a/tests/lib/rules/no-missing-require.js b/tests/lib/rules/no-missing-require.js index c055217c..a59354e1 100644 --- a/tests/lib/rules/no-missing-require.js +++ b/tests/lib/rules/no-missing-require.js @@ -5,7 +5,7 @@ "use strict" const path = require("path") -const RuleTester = require("#eslint-rule-tester").RuleTester +const { RuleTester, isCaseSensitiveFileSystem } = require("#eslint-rule-tester") const rule = require("../../../lib/rules/no-missing-require") const tsReactExtensionMap = [ @@ -396,6 +396,7 @@ ruleTester.run("no-missing-require", rule, { filename: fixture("test.js"), code: "require('./A');", errors: cantResolve("./A"), + skip: !isCaseSensitiveFileSystem, }, // require.resolve