noImportCycles
Summary
Section titled Summary- Diagnostic Category:
lint/nursery/noImportCycles
- This rule doesn’t have a fix.
- The default severity of this rule is warning.
- Sources:
- Same as
import/no-cycle
- Same as
Description
Section titled DescriptionPrevent import cycles.
This rule warns when a file imports another file that, either directly or indirectly, imports the original file again.
Cycles can lead to symbols that are unexpectedly undefined
and are
generally considered poor code hygiene.
If a cycle is detected, it is advised to move code such that imports only go in a single direction, i.e. they don’t point “back” to the importing file.
Examples
Section titled ExamplesInvalid
Section titled Invalidfoobar.js
import { baz } from "./baz.js";
export function foo() { baz();}
export function bar() { console.log("foobar");}
baz.js
import { bar } from "./foobar.js";
export function baz() { bar();}
Valid
Section titled Validfoo.js
import { baz } from "./baz.js";
export function foo() { baz();}
bar.js
export function bar() { console.log("foobar");}
baz.js
import { bar } from "./bar.js";
export function baz() { bar();}
How to configure
Section titled How to configure{ "linter": { "rules": { "nursery": { "noImportCycles": "error" } } }}