Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @ts-ignore
export type { foo } from "../depth-zero";
20 changes: 19 additions & 1 deletion crates/oxc_linter/src/rules/import/no_cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,21 @@ impl Rule for NoCycle {
.iter()
.filter(|entry| entry.module_request.name() == key)
.collect::<Vec<_>>();
if !import_entries.is_empty()

let indirect_export_entries = parent
.indirect_export_entries
.iter()
.filter(|entry| {
entry
.module_request
.as_ref()
.is_some_and(|module_request| module_request.name() == key)
})
.collect::<Vec<_>>();

if (!import_entries.is_empty() || !indirect_export_entries.is_empty())
&& import_entries.iter().all(|entry| entry.is_type)
&& indirect_export_entries.iter().all(|entry| entry.is_type)
{
return false;
}
Expand Down Expand Up @@ -257,6 +270,7 @@ fn test() {
// (r#"import { bar } from "./flow-types-only-importing-type""#, None),
// (r#"import { bar } from "./flow-types-only-importing-multiple-types""#, None),
// (r#"import { bar } from "./flow-typeof""#, None),
(r#"import { foo } from "./typescript/ts-types-re-exporting-type";"#, None),
];

let fail = vec![
Expand Down Expand Up @@ -361,6 +375,10 @@ fn test() {
r#"import { foo } from "./typescript/ts-types-some-type-imports";"#,
Some(json!([{"ignoreTypes":true}])),
),
(
r#"import { foo } from "./typescript/ts-types-re-exporting-type";"#,
Some(json!([{"ignoreTypes":false}])),
),
];

Tester::new(NoCycle::NAME, NoCycle::PLUGIN, pass, fail)
Expand Down
9 changes: 9 additions & 0 deletions crates/oxc_linter/src/snapshots/import_no_cycle.snap
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,12 @@ source: crates/oxc_linter/src/tester.rs
help: These paths form a cycle:
-> ./typescript/ts-types-some-type-imports - fixtures/import/cycles/typescript/ts-types-some-type-imports.ts
-> ../depth-zero - fixtures/import/cycles/depth-zero.js

⚠ eslint-plugin-import(no-cycle): Dependency cycle detected
╭─[cycles/depth-zero.js:1:21]
1 │ import { foo } from "./typescript/ts-types-re-exporting-type";
· ─────────────────────────────────────────
╰────
help: These paths form a cycle:
-> ./typescript/ts-types-re-exporting-type - fixtures/import/cycles/typescript/ts-types-re-exporting-type.ts
-> ../depth-zero - fixtures/import/cycles/depth-zero.js
Loading