import/no-cycle Restriction
무엇을 하나요
Ensures that there is no resolvable path back to this module via its dependencies.
This includes cycles of depth 1 (imported module imports me) to an effectively infinite value, if the maxDepth option is not set.
왜 문제인가요?
Dependency cycles lead to confusing architectures where bugs become hard to find. It is common to import an undefined value that is caused by a cyclic dependency.
예시
이 규칙에서 올바르지 않은 코드 예:
// dep-b.js
import "./dep-a.js";
export function b() {
/* ... */
}// dep-a.js
import { b } from "./dep-b.js"; // reported: Dependency cycle detected.
export function a() {
/* ... */
}In this example, dep-a.js and dep-b.js import each other, creating a circular dependency, which is problematic.
이 규칙에서 올바른 코드 예:
// dep-b.js
export function b() {
/* ... */
}// dep-a.js
import { b } from "./dep-b.js"; // no circular dependency
export function a() {
/* ... */
}In this corrected version, dep-b.js no longer imports dep-a.js, breaking the cycle.
설정
이 규칙은 다음 속성을 갖는 설정 객체를 허용합니다.
allowUnsafeDynamicCyclicDependency
타입: boolean
기본값: false
Allow cyclic dependency if there is at least one dynamic import in the chain
ignoreExternal
타입: boolean
기본값: false
Ignore external modules
ignoreTypes
타입: boolean
기본값: true
Ignore type-only imports
maxDepth
type: integer
default: 4294967295
Maximum dependency depth to traverse
사용 방법
To enable this rule using the config file or in the CLI, you can use:
{
"plugins": ["import"],
"rules": {
"import/no-cycle": "error"
}
}import { defineConfig } from "oxlint";
export default defineConfig({
plugins: ["import"],
rules: {
"import/no-cycle": "error",
},
});oxlint --deny import/no-cycle --import-plugin버전
이 규칙은 v0.0.13에 추가되었습니다.