microsoft / microsoft/TypeScript

Allow to specify import sorting.

オープン
#63,780 コメント 6 件 リアクション 10 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

Awaiting More Feedback Suggestion
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている TypeScript issue と ts-plugin-sort-import-suggestions インターフェースから始め、続いて tsgo の import suggestion の処理と tsconfig.json のオプション解析を見つけます。コンパイラーオプションが moveUpPatterns と moveDownPatterns を受け付け、import suggestion がそれらのパターンを反映し、提案された例を対象とするカバレッジがあれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
go, typescript
領域
developer-experience, tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。