Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad indentation inside anonymous functions when using end-of-line comments #166

Closed
idanarye opened this issue Jul 17, 2015 · 3 comments
Closed
Assignees
Milestone

Comments

@idanarye
Copy link

I'm using end-of-line comments to prevent dfmt from joining lines. This causes some weird results when combined with anonymous functions:

$ echo '
$ echo '
void foo() { //
    void bar() { //
        baz({ //
            qux(); //
        }); //
    } //
} //
' | dfmt --brace_style otbs
void foo() { //
    void bar() { //
        baz({  //
        qux(); //
    }); //
} //
}
 //

Starting from qux(), all lines are one indentation less than what they should be:

  • qux has same indentation as baz
  • The closing }) of the baz invocation has the same indentation as the bar declaration
  • The closing } of the bar declaration has the same indentation as the foo declaration
  • The closing } of the foo declaration has correct indentation - but that's only because you can't indent less...
@Hackerpilot
Copy link
Collaborator

I'm not sure if you knew this, but you can insert // dfmt off and // dfmt on comments to disable formatting for some blocks of code.

@Hackerpilot Hackerpilot added this to the 0.4.0 milestone Aug 10, 2015
@Hackerpilot Hackerpilot self-assigned this Aug 10, 2015
@idanarye
Copy link
Author

I'm trying to use dfmt for indentation - //dfmt off doesn't help here because it distables indentation calculation for the opted-off part:

$ echo '
// dfmt off
void foo() {
    void bar() {
        baz({
// dfmt on
            qux();
        });
    }
}
' | dfmt --brace_style=otbs
// dfmt off
void foo() {
    void bar() {
        baz({
// dfmt on
qux();
});
}
}

@Hackerpilot
Copy link
Collaborator

I meant that you should put // dfmt off before the opening braces and //dfmt on after the closing braces. If you enable formatting like this the formatter will try to match the indent level of the closing braces with the opening braces that you told it to ignore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants