Skip to content
← Back to rules

import/no-cycle Ограничение

Что делает правило

MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 05 HOURS 22 MINUTES 12 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE

Почему это плохо?

MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 05 HOURS 22 MINUTES 11 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE

Примеры

Примеры некорректного кода для этого правила:

javascript
// dep-b.js
import "./dep-a.js";
export function b() {
  /* ... */
}
javascript
// 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.

Примеры корректного кода для этого правила:

javascript
// dep-b.js
export function b() {
  /* ... */
}
javascript
// 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.

Configuration

This rule accepts a configuration object with the following properties:

allowUnsafeDynamicCyclicDependency

type: boolean

default: false

Allow cyclic dependency if there is at least one dynamic import in the chain

ignoreExternal

type: boolean

default: false

Ignore external modules

ignoreTypes

type: boolean

default: 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:

json
{
  "plugins": ["import"],
  "rules": {
    "import/no-cycle": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["import"],
  rules: {
    "import/no-cycle": "error",
  },
});
bash
oxlint --deny import/no-cycle --import-plugin

Версия

Правило добавлено в v0.0.13.

Ссылки