import/no-self-import Suspicious
What it does
Forbids a module from importing itself. This can sometimes happen accidentally, especially during refactoring.
Why is this bad?
Importing a module into itself creates a circular dependency, which can cause runtime issues, including infinite loops, unresolved imports, or undefined values.
Examples
Examples of incorrect code for this rule:
javascript
// foo.js
import foo from "./foo.js"; // Incorrect: module imports itself
const foo = require("./foo"); // Incorrect: module imports itselfExamples of correct code for this rule:
javascript
// foo.js
import bar from "./bar.js"; // Correct: module imports another moduleHow to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny import/no-self-import --import-pluginjson
{
"plugins": ["import"],
"rules": {
"import/no-self-import": "error"
}
}