Skip to content

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

Open
@LeLunZ

Description

@LeLunZ

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)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions