-
Notifications
You must be signed in to change notification settings - Fork 79
feat: add support for arrayExpression.maxWidth configuration
#739
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
xseman
wants to merge
1
commit into
dprint:main
Choose a base branch
from
xseman:array-expression-max-width
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
38 changes: 38 additions & 0 deletions
38
tests/specs/expressions/ArrayExpression/ArrayExpression_MaxWidth.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| ~~ arrayExpression.maxWidth: 50 ~~ | ||
| == should format array elements with max width constraint == | ||
| const values = [0x90, 0x94, 0x19, 0x21, 0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x2d, 0x69, 0x64, 0x09, 0x31, 0x09, 0x31, 0x09, 0x31, 0x30, 0x30, 0x09, 0x45, 0x55, 0x52]; | ||
|
|
||
| [expect] | ||
| const values = [ | ||
| 0x90, 0x94, 0x19, 0x21, 0x72, 0x61, 0x6e, 0x64, | ||
| 0x6f, 0x6d, 0x2d, 0x69, 0x64, 0x09, 0x31, 0x09, | ||
| 0x31, 0x09, 0x31, 0x30, 0x30, 0x09, 0x45, 0x55, | ||
| 0x52, | ||
| ]; | ||
|
|
||
| == should fit short arrays on single line == | ||
| const short = [1, 2, 3]; | ||
|
|
||
| [expect] | ||
| const short = [1, 2, 3]; | ||
|
|
||
| == should handle empty arrays == | ||
| const empty = []; | ||
|
|
||
| [expect] | ||
| const empty = []; | ||
|
|
||
| == should handle single element arrays == | ||
| const single = [0x90]; | ||
|
|
||
| [expect] | ||
| const single = [0x90]; | ||
|
|
||
| == should wrap longer strings appropriately == | ||
| const strings = ["hello", "world", "this", "is", "a", "test", "more"]; | ||
|
|
||
| [expect] | ||
| const strings = [ | ||
| "hello", "world", "this", "is", "a", "test", | ||
| "more", | ||
| ]; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not an accurate way to measure the text of a node because the node could have things like spaces or newlines and bad formatting, so the width might be different once printed. Similarly, in this other PR it's not an accurate way to figure out the node width: https://github.com/dprint/dprint-plugin-typescript/pull/737/changes#diff-d83dd6f700946697666bb782a867b64343578bc2067c1904c08060c5f21009d1R258
Both of these are difficult to do properly and I'm not sure I want to maintain them. Sorry!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback! It would really help me to know if you think these issues (both this one and #737) are actually worth solving within dprint typescript plugin.
If I get clear direction on the approach you'd prefer, I'm happy to implement it, but I don't want to push for features that don't align with your vision for the module. I'd rather spend my time on things you actually find valuable for the project.