3

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.

Luke
  • 20,878
  • 35
  • 119
  • 178

2 Answers2

3

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.

Akasha
  • 969
  • 5
  • 8
2

set 'relative path only' in IDE and remove baseUrl from tsconfig.json

glushkina1
  • 164
  • 2
  • 15