Add a --paren-spacing
option to add whitespace according to WordPress style rules
#2372
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.
This PR adds a
--paren-spacing
option to Prettier that adds whitespace inside()
and[]
parens and inside{}
in JSX attributes and string template arguments. For example:This style is widely used in the WordPress community, e.g., in projects like Calypso, Gutenberg or in Javascript code in WordPress core.
I don't really expect that this PR will ever be merged, as it's directly opposed to the Prettier design principle of adding as few options as possible. It's more likely that we'll be maintaining and updating this patch in a fork.
Its purpose is rather to provide the maintainers with info on how people use and abuse Prettier, and to ask for feedback:
How it works?
Very similar to the existing
bracket-spacing
option: when enabled, add a space (" "
) at the right places, or turn asoftline
intoline
.The patch doesn't support paren spacing in Flow and Typescript constructs, as it's not (yet) used in any our code and I'm not very familiar with their syntax. It should be easy to add at any time though.
There's only one part that's tricky, and that's expanding last function argument:
The last arg's doc sometimes has a
softline/line
at the end, sometimes not. There's a space before the closing)
, sometimes not. To handle all cases correctly, I had to add anaddedLine
option to thegroup
with the formatted last arg, and then check for that option inprintArgumentsList
.