microsoft / microsoft/TypeScript
Allow to specify import sorting.
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
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).
https://github.com/microsoft/TypeScript/issues/51155
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con l’issue di TypeScript collegata e l’interfaccia di ts-plugin-sort-import-suggestions, quindi individua la gestione dei suggerimenti di importazione di tsgo e l’analisi delle opzioni di tsconfig.json. Il lavoro è completato quando un’opzione del compilatore accetta moveUpPatterns e moveDownPatterns e i suggerimenti di importazione riflettono questi pattern, con una copertura per gli esempi proposti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- go, typescript
- Ambito
- developer-experience, tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 30/100