google-java-format icon indicating copy to clipboard operation
google-java-format copied to clipboard

Either require semicolons at the end of enum declarations, or don't

Open dborowitz opened this issue 7 years ago • 3 comments

Currently, gjf accepts either:

enum Foo {
  BAR,
  BAZ;
}

or:

enum Foo {
  BAR,
  BAZ
}

I had a code reviewer tell me to remove the semicolon. I really do not care one way or another, but I would rather not have to discuss it during code reviews. This is exactly what gjf is for, so it'd be nice to take a stand one way or the other.

dborowitz avatar Jan 09 '18 13:01 dborowitz

don't forget

enum Foo {
  BAR,
  BAZ,
  ;
}

which minimizes changed lines on add/remove.

JakeWharton avatar Jan 09 '18 15:01 JakeWharton

The formatter currently makes very few non-whitespace changes. (Fixing imports is the main example, it also reorders modifiers.) There are some technical reasons we've been slow to add more non-whitespaces fixes. Removing unnecessary semicolons is on the list of things we'd like to get to eventually.

cushon avatar Jan 09 '18 15:01 cushon

Point taken that this is different from a whitespace change.

That said, it this case is slightly different from purely unnecessary semicolons. Nobody is going to argue that putting ";;" at the end of every line is desirable, but people do, empirically, argue about this. Fixing ";;" would be more like correcting a typo, whereas this feels more like taking a stand on a should-be-trivial style decision.

dborowitz avatar Jan 09 '18 15:01 dborowitz