On a similar note as the question ESLint - Only Allow Absolute Import Paths Not Relative
How can eslint made to error on absolute imports? Specifically interested in the context of TypeScript.
set 'relative path only' in IDE and remove baseUrl
from tsconfig.json
You could try to use the rule @typescript-eslint/no-restricted-imports
to disallow absolute imports (anything that does not start with ./
or ../
).
{
rules: {
"no-restricted-imports": "off",
"@typescript-eslint/no-restricted-imports": [
"error",
{
"patterns": ["!./*", "!../*"]
}
]
}
}
@typescript-eslint/no-restricted-imports
extends eslint/no-restricted-imports
.
The reason why we disable eslint/no-restricted-imports
is because it can report incorrect errors.
More information here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With