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
Примеры
Примеры некорректного кода для этого правила:
// 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.
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:
{
"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.