diff --git a/crates/oxc_linter/src/rules/import/no_cycle.rs b/crates/oxc_linter/src/rules/import/no_cycle.rs index aaf291be327a8..7e5e4317b0837 100644 --- a/crates/oxc_linter/src/rules/import/no_cycle.rs +++ b/crates/oxc_linter/src/rules/import/no_cycle.rs @@ -109,17 +109,29 @@ impl Rule for NoCycle { .max_depth(self.max_depth) .filter(move |(key, val): (&CompactStr, &Arc), parent: &ModuleRecord| { let path = &val.resolved_absolute_path; + let is_node_module = path .components() .any(|c| matches!(c, Component::Normal(p) if p == OsStr::new("node_modules"))); - let is_type_import = !ignore_types - || !parent + + if is_node_module { + return false; + } + + if ignore_types { + let import_entries = parent .import_entries .iter() .filter(|entry| entry.module_request.name() == key) - .all(|entry| entry.is_type); + .collect::>(); + if !import_entries.is_empty() + && import_entries.iter().all(|entry| entry.is_type) + { + return false; + } + } - is_node_module || is_type_import + true }) .event(|event, (key, val), _| match event { ModuleGraphVisitorEvent::Enter => { @@ -242,6 +254,7 @@ fn test() { // (r#"require(["./es6/depth-one"], d1 => {})"#, Some(json!([{"amd":true}]))), // (r#"define(["./es6/depth-one"], d1 => {})"#, Some(json!([{"amd":true}]))), (r#"import { foo } from "./es6/depth-one-reexport""#, None), + (r#"import { foo } from "./es6/depth-one-reexport""#, Some(json!([{"ignoreTypes":true}]))), (r#"import { foo } from "./es6/depth-two""#, None), (r#"import { foo } from "./es6/depth-two""#, Some(json!([{"maxDepth":2}]))), // (r#"const { foo } = require("./es6/depth-two")"#, Some(json!([{"commonjs":true}]))), diff --git a/crates/oxc_linter/src/snapshots/no_cycle.snap b/crates/oxc_linter/src/snapshots/no_cycle.snap index 2a0b4dac7a714..c115e4558904d 100644 --- a/crates/oxc_linter/src/snapshots/no_cycle.snap +++ b/crates/oxc_linter/src/snapshots/no_cycle.snap @@ -19,6 +19,15 @@ source: crates/oxc_linter/src/tester.rs -> ./es6/depth-one-reexport - fixtures/import/cycles/es6/depth-one-reexport.js -> ../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 "./es6/depth-one-reexport" + · ────────────────────────── + ╰──── + help: These paths form a cycle: + -> ./es6/depth-one-reexport - fixtures/import/cycles/es6/depth-one-reexport.js + -> ../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 "./es6/depth-two"