yapf
yapf copied to clipboard
Add YAPF flag to always line-wrap dictionaries
I am on 0.28 version and have played around with the flags I can find but haven't found anything to 'force' line-wrapping. Specifically I think it would be reasonable for a new flag to allow dictionary statements to always line-wrap, vs I believe the current YAPF logic is to only 'process' line-wrapping configuration settings once a line exceeds the max character limit for a line. In other words, this new flag would enable whatever configuration a user specified for line-wrapping to be applied to ALL dictionaries, even those lines under the max character limit.
With an example, I would like to have this dictionary assignment appear as follows:
# DESIRED
value = {
"Components": [componentPlacement],
"Executives": [executive]
}
Currently, I am unable to find an acceptable* YAPF configuration to result in this multi-line format and instead i get it all on a single line (assuming it's length is less than column_limit):
# UNDESIRED
value = {"Components": [componentPlacement], "Executives": [executive]}
*As implied here, if i set column_limit small enough then the wrapping 'triggers' and works as desired, BUT I wish to in general have a longer line limit.
Add a comma at the end of "Executives": [executive] to enforce putting all dicts on separate lines for the given code block.
Or set FORCE_MULTILINE_DICT: True; e.g.:
$ pipx run yapf --no-local-style --style="{FORCE_MULTILINE_DICT: True}" 2> /dev/null <<EOF
value = {
"Components": [componentPlacement],
"Executives": [executive]
}
EOF
value = {
"Components": [componentPlacement],
"Executives": [executive]
}