Alignment of horizontally-formatted enum struct variants
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず、関連するオプション struct_field_align_threshold と enum_discrim_align_threshold が rustfmt でどのように実装・テストされているかを調べます。水平方向にフォーマットされた enum の struct バリアントがどのように処理されるかを追跡し、その後、しきい値の上限・下限、max_width、デフォルトで無効な値、整列された出力について、設定の動作とテストを定義します。
索引モデルが issue の本文から書いたものです。
説明
Feature Request
struct_variant_align_threshold
Summary
For applicable, horizontally-formatted branches of an enum with struct variants, aligns them by adding padding space after each branch name, so all struct variants start at the same column (one space after the longest branch name). This is used in good combination with the stable option struct_variant_width.
When enabled, this is applied to all branches when their name is shorter than threshold, and adding the padding does not exceed max_width. The default value would be 0 to disable it, with any nonnegative integer as a possible value.
Motivation
A good example is an enum where many struct variants have the same or similar fields, allowing for much greater readability of the branch names. This is particularly common on enums that have many shared fields, and many, many variants. An example is the Instruction enum on uutils awk:
Original (snippet):
pub enum Instruction {
Record { dest: Reg, arg: Arg, ty: ArgTy },
Negation { dest: Reg, arg: Arg, ty: ArgTy },
ToInt { dest: Reg, arg: Arg, ty: ArgTy },
Negative { dest: Reg, arg: Arg, ty: ArgTy },
...
Matches { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
MatchesNot { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Add { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Subtract { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
...
}
Formatted (new):
pub enum Instruction {
Record { dest: Reg, arg: Arg, ty: ArgTy },
Negation { dest: Reg, arg: Arg, ty: ArgTy },
ToInt { dest: Reg, arg: Arg, ty: ArgTy },
Negative { dest: Reg, arg: Arg, ty: ArgTy },
...
Matches { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
MatchesNot { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Add { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
Subtract { dest: Reg, lhs: Arg, rhs: Arg, tyr: ArgTy, tyl: ArgTy },
...
}
Note: I know this particular case can be solved using a newtype or an alias, but we have our reasons for it to be this way in the real codebase. Believe me, this enum was not born this way.
Related configuration options
struct_field_align_threshold, enum_discrim_align_threshold
- 主要言語
- Rust
- スター
- 7.1k
- フォーク
- 1.2k
- 平均マージ
- 1日 4時間
- マージ済み PR(30日)
- 20
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
rust-lang/rustfmt のほかの issue
-
A-config C-bug SO-print-config
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
メンテナーはふだん 1 日以内に返信
-
A-Unicode C-bug P-low
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
rust-lang/rustfmt#7210 · コメント 5 件 ·
メンテナーはふだん 1 日以内に返信
-
A-imports C-bug E-hard I-non-idempotency X-impacts-stable-default-format
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
rust-lang/rustfmt#7173 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
A-comments C-bug only-with-option UO-indent_style
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Fix `first_line_width` to be tab-aware再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンA-tabs A-whitespace C-bug SO-hard_tabs
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
rust-lang/rustfmt の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
tamatebako/tebako#1155 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
swc-project/swc-next-issues#1148 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
registrystack/registry-stack#2828 ·
メンテナーはふだん 1 日以内に返信
-
agent:triaged arch-audit bug priority:p1
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
SocketDev/socket-patch#2364 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug P2
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信