import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support path mapping/aliases and relative paths.

SanteeMarcel opened this issue · comments

I am using the folllowing config:

{
  "env": {
    "es2021": true,
    "commonjs": true,
    "node": true
  },
  "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "plugin:import/typescript"],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module",
    "project": "tsconfig.json"
  },
  "plugins": ["@typescript-eslint", "import"],
  "rules": {
    "import/no-restricted-paths": [
      "error",
      {
        "zones": [
          { "target": "./src/project/SiteA", "from": "./src/project/SiteB" },
          { "target": "./src/project/SiteB", "from": "./src/project/Site" }
        ]
      }
    ]
  }
}

But my tsconfig.json has some mapping, that are bypassing the rule:

    "paths": {
      "@siteA": ["src/project/SiteA"],
      "@siteB": ["src/project/SiteB"],
 }

So this is perfectly valid code, when I don't want it to be:

// I am on src/project/SiteA
import { component } from '@siteB/componente

How should I approach this?

If you're using TypeScript, you need eslint-import-resolver-typescript.

Please read README carefully.