Skip to content

Commit 39adefe

Browse files
authored
fix(linter): handle re-exporting of type correctly in import/no-cycle (#10606)
Handle re-exporting of type correctly in import/no-cycle lint rule. Added one passing test (ignoreTypes = default/true) and one failing test (ignoreTypes = false). Closes #10547
1 parent 7c85ae7 commit 39adefe

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @ts-ignore
2+
export type { foo } from "../depth-zero";

crates/oxc_linter/src/rules/import/no_cycle.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,21 @@ impl Rule for NoCycle {
142142
.iter()
143143
.filter(|entry| entry.module_request.name() == key)
144144
.collect::<Vec<_>>();
145-
if !import_entries.is_empty()
145+
146+
let indirect_export_entries = parent
147+
.indirect_export_entries
148+
.iter()
149+
.filter(|entry| {
150+
entry
151+
.module_request
152+
.as_ref()
153+
.is_some_and(|module_request| module_request.name() == key)
154+
})
155+
.collect::<Vec<_>>();
156+
157+
if (!import_entries.is_empty() || !indirect_export_entries.is_empty())
146158
&& import_entries.iter().all(|entry| entry.is_type)
159+
&& indirect_export_entries.iter().all(|entry| entry.is_type)
147160
{
148161
return false;
149162
}
@@ -257,6 +270,7 @@ fn test() {
257270
// (r#"import { bar } from "./flow-types-only-importing-type""#, None),
258271
// (r#"import { bar } from "./flow-types-only-importing-multiple-types""#, None),
259272
// (r#"import { bar } from "./flow-typeof""#, None),
273+
(r#"import { foo } from "./typescript/ts-types-re-exporting-type";"#, None),
260274
];
261275

262276
let fail = vec![
@@ -361,6 +375,10 @@ fn test() {
361375
r#"import { foo } from "./typescript/ts-types-some-type-imports";"#,
362376
Some(json!([{"ignoreTypes":true}])),
363377
),
378+
(
379+
r#"import { foo } from "./typescript/ts-types-re-exporting-type";"#,
380+
Some(json!([{"ignoreTypes":false}])),
381+
),
364382
];
365383

366384
Tester::new(NoCycle::NAME, NoCycle::PLUGIN, pass, fail)

crates/oxc_linter/src/snapshots/import_no_cycle.snap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,12 @@ source: crates/oxc_linter/src/tester.rs
270270
help: These paths form a cycle:
271271
-> ./typescript/ts-types-some-type-imports - fixtures/import/cycles/typescript/ts-types-some-type-imports.ts
272272
-> ../depth-zero - fixtures/import/cycles/depth-zero.js
273+
274+
eslint-plugin-import(no-cycle): Dependency cycle detected
275+
╭─[cycles/depth-zero.js:1:21]
276+
1import { foo } from "./typescript/ts-types-re-exporting-type";
277+
· ─────────────────────────────────────────
278+
╰────
279+
help: These paths form a cycle:
280+
-> ./typescript/ts-types-re-exporting-type - fixtures/import/cycles/typescript/ts-types-re-exporting-type.ts
281+
-> ../depth-zero - fixtures/import/cycles/depth-zero.js

0 commit comments

Comments
 (0)