Skip to content

Commit

Permalink
feat(import-target): Add resolution error reason
Browse files Browse the repository at this point in the history
  • Loading branch information
aladdin-add committed May 6, 2024
1 parent f9e454d commit 86b6cd7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
19 changes: 19 additions & 0 deletions tests/eslint-rule-tester.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand All @@ -38,5 +43,19 @@ 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) {
const skip = typeof item === "string" ? false : item.skip
delete item.skip
return skip === void 0 || skip === false
}
3 changes: 2 additions & 1 deletion tests/lib/rules/no-missing-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (() => {
Expand Down Expand Up @@ -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,
},

{
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/rules/no-missing-require.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -396,6 +396,7 @@ ruleTester.run("no-missing-require", rule, {
filename: fixture("test.js"),
code: "require('./A');",
errors: cantResolve("./A"),
skip: !isCaseSensitiveFileSystem,
},

// require.resolve
Expand Down

0 comments on commit 86b6cd7

Please sign in to comment.