跳转到内容

noImportCycles

此内容尚不支持你的语言。

Prevent 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.

foobar.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();
}

foo.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();
}
biome.json
{
"linter": {
"rules": {
"nursery": {
"noImportCycles": "error"
}
}
}
}