Menu

#395 Breaking elseif with 1TBS does not add brackets.

closed-fixed
2017-01-14
2016-04-18
Xorcist
No

When using --style=1tbs --indent=spaces=2 --break-elseifs --add-brackets --mode=cs

to format the following code:

      if (cond1) {
         code1
      } else if (cond2) {
         code2
      } else if (cond3) {
         code3
      }

the resulting code is:

    if (cond1) {
       code1
    } else
      if (cond2) {
        code2
      } else
        if (cond3) {
          code3
        }

but... I would expect it to be:

    if (cond1) {
       code1
    } else {
      if (cond2) {
        code2
      } else {
        if (cond3) {
          code3
        }
      }
    }

I couldnt' find any combination of settings that got me to that result, so I'm assuming this is a bug.

If this is not a bug, can someone explain how to get the enclosing bodies for each else.

Discussion

  • Jim Pattee

    Jim Pattee - 2016-04-19
    • status: open --> open-fixed
    • assigned_to: Jim Pattee
    • Priority: 5 --> 7
     
  • Jim Pattee

    Jim Pattee - 2016-04-19

    Adding brackets for each else can change the results of the statement.
    For this reason it isn't done.

     
  • Xorcist

    Xorcist - 2016-04-19

    Well if the brackets are not present, then it's not 1TBS.

    Can you provide an exampe of when breaking an elseif into an else + if with appropriate bracketing for the else body, and the if body, would change the results? As I don't see how this is possible (pending the brackets are put in place properly).

    Are you saying it's not possible to programmitcally add the brackets properly?

     

    Last edit: Xorcist 2016-04-19
  • Jim Pattee

    Jim Pattee - 2017-01-14
    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

Auth0 Logo