'ESLint - Only Allow Relative Import Paths Not Absolute
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Akasha |
