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

Formatter doesn't honor "else if" #17363

Closed
DartBot opened this issue Mar 10, 2014 · 4 comments
Closed

Formatter doesn't honor "else if" #17363

DartBot opened this issue Mar 10, 2014 · 4 comments
Assignees
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@DartBot
Copy link

DartBot commented Mar 10, 2014

This issue was originally filed by @tatumizer


BEFORE:
main() {
  var zero = 0;
  if (0 == 0) {
    zero=0;
  } else if (0 == 1) {
    zero=1;
  } else if (0 == 2) {
    zero =2;
  }
  print(0);
}
AFTER:
main() {
  var zero = 0;
  if (0 == 0) {
    zero = 0;
  } else {
    if (0 == 1) {
      zero = 1;
    } else {
      if (0 == 2) {
        zero = 2;
      }
    }
  }
  print(0);
}

A lot of unnecessary "{}" inserted. Apparently, formatter doesn't think of "else if" as a valid construct, but it is.
Note it's not the same problem as orphans as per issue #16847.
In the latest dev release, orphans produce the same output as above, that is
foo() {
  var zero = 0;
  if (0 == 0)
    zero=0;
  else if (0 == 1)
    zero=1;
  else if (0 == 2)
    zero =2;
 
  print(0);
}
is now formatted exactly as in AFTER section above, inserting unnecessary {}. Whereas it was supposed to insert minimal amount of {}, so that the thing after formatting should look as in BEFORE example above.

Another small issue: I had to insert print(0) in the end; without it, formatter prints red error message at the bottom: expected EOF but got '}'

@DartBot
Copy link
Author

DartBot commented Mar 10, 2014

This comment was originally written by @tatumizer


Please change the title, it sounds rude with respect to formatter. Something like: formatter doesn't honor "else if". My apologies.
/Alex

@pq
Copy link
Member

pq commented Mar 10, 2014

Thanks for the report. I updated the title as you suggested but I think the first one wasn't too far off. Looks like mangling to me!

I've upped the priority too since this breaks the basic contract (e.g., formats should be semantic preserving).


Set owner to @pq.
Added this to the 1.3 milestone.
Removed Priority-Unassigned label.
Added Priority-High, Area-Formatter, Triaged labels.
Changed the title to: "Formatter doesn't honor "else if"".

@pq
Copy link
Member

pq commented Mar 12, 2014

Fixed w/ r33613.


Added Fixed label.

@DartBot DartBot added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures labels Mar 12, 2014
@DartBot DartBot added this to the 1.3 milestone Mar 12, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-lang/dart_style#333.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

2 participants