google / yapf

A formatter for Python files
Apache License 2.0
13.78k stars 891 forks source link

Hang closing brackets #605

Open fpagnoux opened 6 years ago

fpagnoux commented 6 years ago

Hey everyone,

Thanks for developing this tool! I'm trying to use in a project where the code style is to hang closing parenthesis. That's the E133 rule from pep8, that can be enabled with the --hang-closing option . For instance, we prefer:

y = {
    'a': 1,
    'b': 2,
    'c': 3,
    'd': 4,
    }

over

y = {
    'a': 1,
    'b': 2,
    'c': 3,
    'd': 4,
}

I'm trying to set up yapf to enforce this, but it seems to always dedent the closing brackets... I thought setting align_closing_bracket_with_visual_indent to true was precisely made for this, but it doesn't seem to change anything...

Am I doing something wrong? Can I make yapf enforce hanging closing brackets? Thanks in advance!

fpagnoux commented 6 years ago

My .style.yapf:

[style]
based_on_style = pep8
align_closing_bracket_with_visual_indent = true
warsaw commented 5 years ago

I'm having a similar problem. I've tried align_closing_bracket_with_visual_indent=true and dedent_closing_brackets=false separately and in combination. Despite the implication of those setting names, neither seems to produce hanging braces. yapf 0.28.0

ergoithz commented 3 years ago

It looks like, for formatting, the rule to effectively control this specific behavior is

indent_closing_brackets = true