Skip to content

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

@vrosa

Description

@vrosa

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions