feat(linter/import): ignore type-only imports and exports in no_unresolved (#2849)

fa60e3d738/src/rules/no-unresolved.js (L32-L35)
This commit is contained in:
Dunqing 2024-03-29 19:54:45 +08:00 committed by GitHub
parent 1b5e544a36
commit 76cc90684a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 10 deletions

View file

@ -55,6 +55,10 @@ impl Rule for NoUnresolved {
}
for requested_module in requested_modules {
// ignore type-only imports and exports
if requested_module.is_type() {
continue;
}
ctx.diagnostic(NoUnresolvedDiagnostic(requested_module.span()));
}
}
@ -102,6 +106,9 @@ fn test() {
r"require(foo)",
// Unsupported extensions
r#"import "./test.png""#,
// ignore type-only imports and exports
r"import type { m } from 'mod'",
r"export type * from 'mod'",
];
let fail = vec![
@ -128,7 +135,7 @@ fn test() {
];
Tester::new(NoUnresolved::NAME, pass, fail)
.change_rule_path("index.js")
.change_rule_path("index.ts")
.with_import_plugin(true)
.test_and_snapshot();
}

View file

@ -3,55 +3,55 @@ source: crates/oxc_linter/src/tester.rs
expression: no_unresolved
---
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:24]
╭─[index.ts:1:24]
1 │ import reallyfake from "./reallyfake/module"
· ─────────────────────
╰────
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:17]
╭─[index.ts:1:17]
1 │ import bar from './baz';
· ───────
╰────
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:17]
╭─[index.ts:1:17]
1 │ import bar from './baz';
· ───────
╰────
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:17]
╭─[index.ts:1:17]
1 │ import bar from './empty-folder';
· ────────────────
╰────
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:22]
╭─[index.ts:1:22]
1 │ import { DEEP } from 'in-alternate-root';
· ───────────────────
╰────
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:21]
╭─[index.ts:1:21]
1 │ export { foo } from "./does-not-exist"
· ──────────────────
╰────
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:15]
╭─[index.ts:1:15]
1 │ export * from "./does-not-exist"
· ──────────────────
╰────
⚠ eslint-plugin-import(no-unresolved): Ensure imports point to a file/module that can be resolved
╭─[index.js:1:22]
╭─[index.ts:1:22]
1 │ export * as bar from "./does-not-exist"
· ──────────────────
╰────
× Unexpected token
╭─[index.js:1:8]
╭─[index.ts:1:8]
1 │ export bar from "./does-not-exist"
· ───
╰────