microsoft / microsoft/TypeScript
Allow to specify import sorting.
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem verknüpften TypeScript-Issue und der Schnittstelle von ts-plugin-sort-import-suggestions. Suche anschließend tsgo's Verarbeitung von Importvorschlägen und das Parsen der Optionen in tsconfig.json. Als abgeschlossen gilt die Arbeit, wenn eine Compileroption moveUpPatterns und moveDownPatterns akzeptiert und Importvorschläge diese Muster widerspiegeln, mit Testabdeckung für die vorgeschlagenen Beispiele.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- go, typescript
- Bereich
- developer-experience, tooling
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100