Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix long imports by exchanging with alias/paths from tsconfig #3007

Open
LeLunZ opened this issue May 14, 2024 · 1 comment
Open

fix long imports by exchanging with alias/paths from tsconfig #3007

LeLunZ opened this issue May 14, 2024 · 1 comment

Comments

@LeLunZ
Copy link

LeLunZ commented May 14, 2024

Hey.

I am currently working on an nx project. Where in the tsconfig something like that is configured:

    "compilerOptions": {
        "paths": {
            "@auth/feature-auth": ["libs/auth/feature-auth/src/index.ts"],
            "@employee-view/api": ["libs/employee-view/api/src/index.ts"],
            "@employee-view/shared": ["libs/employee-view/shared/src/index.ts"],
            "@shared/map": ["libs/shared/map/src/index.ts"],
            "@ui-library/*": ["libs/ui-library/src/lib/*"],
        }
    }

Then in the code somewhere in the project there is an import like:

import { ZipCodeUtilsService } from '../../../../../shared/map/src/lib/services/zip-code-utils.service';

Which could be shortened to

import { ZipCodeUtilsService } from '@shared/map';

I guess I want something similar to what my IDE is doing.
Currently my IDE (WebStorm) shows a suggestion like that, but I guess thats WebStorm specific. And I can't run eslint --fix to do that:
Screenshot 2024-05-14 at 13 03 43

Is that already possible with a eslint rule or is that a possible improvement to this package? (I guess it would fit into import/no-useless-path-segments)

@ljharb
Copy link
Member

ljharb commented May 16, 2024

no-useless-path-segments can only check relative filesystem paths. There's no good way to be sure what aliases might be doing and how they can be altered in a reliable way, that I can think of.

WebStorm's suggestions could be made as eslint rule suggestions, but not as an autofix. Additionally, that'd be a rule option that only applied when using TS, so I'm not sure it's a good fit for this plugin.

Does the TS-eslint plugin not have a rule that can cover this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants