oxc/crates
John Daly 5abbb0cada
fix(linter): import/no-cycle ignore type-only imports (#2924)
A fix for the work done in: https://github.com/oxc-project/oxc/pull/2905

The existing code checks if _all_ import entries in a ModuleRecord are
type-only, when determining if the ModuleRecord should be skipped when
checking for cycles. This is incorrect.

To demonstrate the problem: Running the `no-cycles` rule, with
`ignoreTypes` enabled, on the following example code will cause a cycle
to be reported between Module A and Module B

```typescript
// Module A
import type { Bar } from './b';
import { Baz } from './c'

// Module B
import type { Foo } from './a';

// Module C
export const Baz = 'baz';
```

The reason this is happening is because the import to Module C in Module
A is causing the `was_imported_as_type` variable to evaluate to `false`,
since the Module C import is not type-only.

What we actually want to do is skip visiting Module B entirely, by
checking if its import request from Module A is type-only.

This PR fixes the logic so that only the import entries for the next
ModuleRecord are considered when determining `was_imported_as_type`.
2024-04-09 12:38:15 +08:00
..
oxc Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_allocator Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_ast Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_cli chore: only build the allocators in release mode because they are slow to build (60s) 2024-04-02 17:39:01 +08:00
oxc_codegen Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_diagnostics Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_index Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_js_regex refactor: rename CompactString to CompactStr (#2619) 2024-03-06 12:24:23 +08:00
oxc_language_server chore: apply cargo autoinherit (#2826) 2024-03-26 23:57:50 +08:00
oxc_linter fix(linter): import/no-cycle ignore type-only imports (#2924) 2024-04-09 12:38:15 +08:00
oxc_macros chore: bump syn to v2 (#2888) 2024-04-02 20:57:09 +08:00
oxc_minifier Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_module_lexer refactor(ast): add walk_mut functions (#2776) 2024-03-25 20:40:13 +03:30
oxc_parser Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_prettier chore: guard against unsafe code as much as possible. 2024-04-03 19:35:07 +08:00
oxc_semantic Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_sourcemap Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_span Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_syntax Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_transformer Release crates v0.12.2 2024-04-08 11:13:13 +08:00
oxc_wasm feat(transformer): add transform-typescript boilerplate (#2866) 2024-03-30 20:48:35 +08:00