yapf icon indicating copy to clipboard operation
yapf copied to clipboard

Add YAPF flag to always line-wrap dictionaries

Open aamailhot opened this issue 3 years ago • 1 comments
trafficstars

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.

aamailhot avatar Apr 19 '22 15:04 aamailhot

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]
}

Spitfire1900 avatar Jun 16 '23 18:06 Spitfire1900