Skip to content

Wrong indentation of 'break' #663

Closed
Closed

Description

@Yraine

Empty config.

Simple case, before formatting:

void test1( int n )
{
    switch ( n )
    {
    case 1:
    {
        std::cout << "1" << std::endl;
    }
    break;
    }
}

void test2( int n )
{
    switch ( n )
    {
    case 1:
    { std::cout << "1" << std::endl; }
    break;
    }
}

After formatting:

void test1( int n )
{
    switch ( n )
    {
    case 1:
    {
        std::cout << "1" << std::endl;
    }
    break;
    }
}

void test2( int n )
{
    switch ( n )
    {
    case 1:
    { std::cout << "1" << std::endl; }
                                 break;
    }
}

'break' in test1 is ok.
'break' in test2 has a wrong indentation.

Activity

  1. mihaipopescu commented on Sep 2, 2016

    @mihaipopescu
    Collaborator

    Thanks for reporting. Can you clarify if this is before or after formatting ?

  2. Yraine commented on Sep 2, 2016

    @Yraine
    Author

    Sorry, you are right! :)

    Before:

    void test2( int n )
    {
        switch ( n )
        {
        case 1:
        { std::cout << "1" << std::endl; }
        break;
        }
    }
    

    After:

    void test2( int n )
    {
        switch ( n )
        {
        case 1:
        { std::cout << "1" << std::endl; }
                                     break;
        }
    }
    
  3. mihaipopescu commented on Sep 2, 2016

    @mihaipopescu
    Collaborator

    I guess you'll need to find the proper combination of options to achieve your wanted formatting. What is your expected formatting result ?

  4. Yraine commented on Sep 2, 2016

    @Yraine
    Author

    In my real configuration, I use those options:

    indent_with_tabs   = 0
    indent_columns     = 4
    indent_switch_case = 4
    indent_case_brace  = 4
    

    Code before formatting (expected unchanged after formatting):

    void test()
    {
        switch ( n )
        {
            case 1:
                std::cout << "1";
                break;
    
            case 2:
                {
                    std::cout << "2";
                }
                break;
    
            case 3:
                { std::cout << "3"; }
                break;
        }
    }
    

    After formatting I obtain this:

    void test()
    {
        switch ( n )
        {
            case 1:
                std::cout << "1";
                break;
    
            case 2:
                {
                    std::cout << "2";
                }
                break;
    
            case 3:
                { std::cout << "3"; }
                                    break;
        }
    }
    

    It seems strange the position of the last 'break'.

  5. mihaipopescu commented on Sep 2, 2016

    @mihaipopescu
    Collaborator

    uh ok, you're right ! It probably thinks it's an oneliner and it doesn't add newlines and the indentation is dependent on the previous brace close. Can you play with oneliner options as a workaround ?

  6. Yraine commented on Sep 2, 2016

    @Yraine
    Author

    I set all *_leave_one_liners options to false, but that line always remains unchanged. Probably I miss the right option (or I didn't understand your suggestion).
    Anyway, it's not a great problem, I can manually change my code for the moment.

    PS: Thanks for your patience! :D

  7. added 2 commits that reference this issue on Dec 22, 2016
  8. zeule commented on Apr 5, 2017

    @zeule

    I have a similar issue. My configuration is:

    indent_with_tabs		= 0
    indent_columns	    	= 4
    indent_switch_case		= 0
    indent_case_shift		= 0
    indent_case_brace		= 4
    

    The following example:

    switch (var) {
    case 1: {
        }
        anything;
        break;
    }
    
    switch (var) {
    case 1: {
        }
        break;
    }

    uncrustify trasforms into:

    switch (var) {
    case 1: {
        }
        anything;
        break;
    }
    
    switch (var) {
    case 1: {
        }
            break;
    }

    There seems to be a problem when there is nothing between closing brace and break. And when
    mod_move_case_break = true, the indentation of 'break' is the same, but inside the braces:

    switch (var) {
    case 1: {
            break;
        }
    }
  9. guy-maurel commented on Apr 27, 2017

    @guy-maurel
    Contributor

    This is correct, as wished from invisible-clew.
    break becomes the indentation of the opening brace if the previous is a closing brace.

  10. zeule commented on Apr 27, 2017

    @zeule

    What can I do to disable this, please?

  11. guy-maurel commented on May 27, 2017

    @guy-maurel
    Contributor

    uncrustify cannot do disable.

  12. mihaipopescu commented on Jun 5, 2017

    @mihaipopescu
    Collaborator

    That doesn't mean that we should fix issues as per "first come first served". @evsh please state your case in another issue.

  13. Krizai commented on Jun 28, 2017

    @Krizai
    Contributor

    Experiencing the same issue

    + (void)analyticsEventForType:(int)eventType
    {
        switch (eventType) {
            case 2: {
                eventName = @"1";
            }
            break;
    
            case 1: {
                eventName = @"1";
            }
            break;
    
        }
    
    }
    

    becomes

    + (void)analyticsEventForType:(int)eventType
    {
        switch (eventType) {
            case 2: {
                eventName = @"1";
            }
                    break;
    
            case 1: {
                eventName = @"1";
            }
                    break;
    
        }
    
    }
    
    
  14. mihaipopescu commented on Jun 28, 2017

    @mihaipopescu
    Collaborator

    I think it's time to create a new issue referencing back this one.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions