Skip to content

CalmDownVal/eslint-import-resolver

Repository files navigation

eslint-import-resolver-typescript

This is a re-implementation of eslint-import-resolver-typescript (ISC license) by Alex Gorbatchev.

This version adds logic to take the location of tsconfig into account and won't apply path mapping outside of its package.

Example

├─ packages
│  ├─ client
│  │  ├─ src
│  │  │  └─ utils
│  │  │     └─ constants.ts
│  │  ├─ package.json
│  │  └─ tsconfig.json
│  └─ server
│     ├─ src
│     │  └─ utils
│     │     └─ constants.ts
│     ├─ package.json
│     └─ tsconfig.json
├─ .eslintrc
└─ package.json

Assume ~/* maps to the src directory in both packages. Since the original implementation uses all tsconfigs at once, resolving ~/utils/constants yields two paths:

  • packages/client/src/utils/constants.ts
  • packages/server/src/utils/constants.ts

The original version then blindly returns the first one found, which means the resolution works correctly only for the first package. For the second package, the resolution algorithm will point to the wrong file.

This version considers the location of tsconfig and won't apply path patterns defined in configs that don't relate to the file being linted.

Debugging

To show debug logs from this resolver, run ESLint with the DEBUG environment variable set:

# Bash
DEBUG="eslint-import-resolver-typescript" yarn eslint .

# PowerShell
& { $env:DEBUG='eslint-import-resolver-typescript'; yarn eslint . }

Changelog

  • 1.2.0
    • Updated to work with Yarn's PnP loader.
  • 1.1.0
    • Fixed resolution for projects with nested TS config files.
  • 1.0.0
    • Initial implementation.