Repository navigation
Conversation
xseman
commented
Sep 25, 2025
Contributor
Author
|
@dsherret I know you may be busy. This PR has been open for a while. Any feedback would help. Thanks |
xseman
force-pushed
the
align-assignments
branch
5 times, most recently
from
November 11, 2026 05:44
8c801a9 to
5f27bc2
Compare
xseman
force-pushed
the
align-assignments
branch
from
November 11, 2026 09:35
5f27bc2 to
5f4179a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #483
Adds an opt-in
alignAssignmentsoption (defaultfalse) that aligns values the way gofmt does:It applies to variable statements, class properties, enum members, object properties, and interface and type literal members. A member without a value is aligned on its type (
declare const X: T;).Behavior
The grouping follows gofmt (
go/printer):a = 1;) aren't aligned.The one difference: dprint has a line width, so the alignment only adds spaces and never moves a line break. A member that would go over the line width isn't aligned.
Implementation
The widths are measured from the file text, so
format_textandformat_parsed_sourceformat without the alignment first and then align that output. It only happens when the option is on and costs about 2x the formatting time. I also tried measuring at print time in one pass, but it left files unstable and was 2.6x slower.Validation
On 59,021 TypeScript files (DefinitelyTyped, vscode, bun, deno std, …) with the option on: 0 panics, 0 outputs that don't parse, 0 files that change when formatted again, and 0 files where anything other than spaces differs from the default output. With the option off, the output is byte-identical to
main.The option name is open to change, and I can add per-node options if you'd prefer them.