Skip to content

Commit

Permalink
feat(linter/import): ignore type-only imports and exports in no_unres…
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunqing committed Mar 29, 2024
1 parent 1b5e544 commit 76cc906
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
9 changes: 8 additions & 1 deletion crates/oxc_linter/src/rules/import/no_unresolved.rs
Expand Up @@ -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()));
}
}
Expand Down Expand Up @@ -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![
Expand All @@ -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();
}
18 changes: 9 additions & 9 deletions crates/oxc_linter/src/snapshots/no_unresolved.snap
Expand Up @@ -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]
1import 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]
1import 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]
1import 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]
1import 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]
1import { 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]
1export { 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]
1export * 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]
1export * as bar from "./does-not-exist"
· ──────────────────
╰────

× Unexpected token
╭─[index.js:1:8]
╭─[index.ts:1:8]
1export bar from "./does-not-exist"
· ───
╰────

0 comments on commit 76cc906

Please sign in to comment.