mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
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:
parent
1b5e544a36
commit
76cc90684a
2 changed files with 17 additions and 10 deletions
|
|
@ -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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
· ───
|
||||
╰────
|
||||
|
|
|
|||
Loading…
Reference in a new issue