eslint-plugin-ban-relative-imports
v0.1.1
Published
Disallow relative imports, and automatically convert them into absolute imports.
Readme
eslint-plugin-ban-relative-imports
Usage
You must have a tsconfig.json file in the root of your project.
The tsconfig.json file must have a baseUrl property, which is the directory that all
relative imports will be resolved against.
and paths property, which is an object that maps relative imports to absolute imports.
For example, if your tsconfig.json file looks like this:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
}
}Then you can import from src/components/Button.tsx as import Button from "@/components/Button.tsx".
Installation
npm install -D eslint-plugin-ban-relative-imports...
import banRelativeImports from "eslint-plugin-ban-absolute-imports"
export default tseslint.config(
...
{
...
plugins: {
...
"ban-relative-imports": banRelativeImports,
},
rules: {
...
"ban-relative-imports/ban-relative-imports": "error",
}
}
)Known issues
Do not run eslint using Bun.
