yapf icon indicating copy to clipboard operation
yapf copied to clipboard

Hang closing brackets

Open fpagnoux opened this issue 7 years ago • 3 comments

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 avatar Aug 22 '18 15:08 fpagnoux

My .style.yapf:

[style]
based_on_style = pep8
align_closing_bracket_with_visual_indent = true

fpagnoux avatar Aug 22 '18 15:08 fpagnoux

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

warsaw avatar Jul 18 '19 17:07 warsaw

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

indent_closing_brackets = true

ergoithz avatar Sep 02 '21 14:09 ergoithz