vitonsky / eslint-plugin-paths

A plugin for ESLint, to force use paths aliases from tsconfig
https://www.npmjs.com/package/eslint-plugin-paths
Apache License 2.0
48 stars 0 forks source link

`eslint --fix` does not work properly if `baseUrl` is omitted #75

Open vrosa opened 3 months ago

vrosa commented 3 months ago

First of all, thanks for creating this plugin, it is really useful.

I'd like to report that if the tsconfig.json file does not contain the compilerOptions.baseUrl property, eslint --fix incorrectly updates affected files. For instance, for the following config:

{
  "compilerOptions": {
    "paths": {
       "~/routers/*": ["./src/routers/*"],
    }
  }
}

And the following import in .src/tests/test/test.ts to import ./src/routers/userRouter.ts:

import { userRouter } from '../../routers/userRouter';

When you run eslint, it shows the error Update import to ~/uters/userRouter, that is, it cuts off the first 2 characters from the alias. Running eslint --fix then updates the file with the wrong and invalid import { userRouter } from '~/uters/userRouter'; import statement. The workaround is to set a baseUrl field so paths under paths can be absolute; however, it's not ideal because baseUrl has other side effects, such as potential module resolution conflicts with node_modules.

vitonsky commented 3 months ago

Thank you for report. It is a known intermediate problem, but i did not known about potential problems due to baseUrl option.

Will be fixed in next release.