Allow to specify import sorting.
Opened this issue · 0 comments
Typescript has this long running issue full of complaints about how there's no way to prefer certain import paths over others, and in any non-trivially sized application, path aliasing is bound to clash with the various library imports available (hence the practice of having a path alias @/ to get at all first-party application imports).
A plugin was suggested multiple times in the above issue, which has a very simple interface to configure around this: https://github.com/tidalhq/ts-plugin-sort-import-suggestions
I think this is something that should be included in tsgo itself, for two reasons:
- It's not just some fringe preference, everyone at some point will want to prefer certain import path prefixes over others
- It's an extremely simple thing to implement
I propose being able to add to tsconfig.json a configuration item like this:
{
"compilerOptions": {
"importSorting": {
// Matches `@/`, `../` and `./`, move them up in the suggestions (This is the default config if you leave it empty)
"moveUpPatterns": ["@/", "\\.{1,2}/"],
// Move `dist` down in the suggestions, by default it's `[]`
"moveDownPatterns": ["dist"],
]
},
}
This is a flexible and performant approach that will handle pretty much everyone's needs. I don't know why this was left to be a plugin when it's such a critical piece of an ergonomic Typescript-based development environment.