-
Notifications
You must be signed in to change notification settings - Fork 857
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
Should the formatter also add missing braces #51
Comments
…rmat -i Also, fix missing braces (as formatter didn't do that - see google/google-java-format#51)
Yes, adding braces is a request we're considering (there are some concerns unique to making non-whitespace changes that we'd have to sort through). In the meantime, the current behavior is acceptable, because (a) it's exactly what users following AOSP style want, and (b) for Google Style the code was already incorrect anyway, and maybe the odd change will prompt a human to make the right fix. |
Any update on this? I keep having to resolve flame wars between those who want what the Google style guide says vs. what the tools actually enforce. |
Will this be fixed anytime soon? |
This feature would be really helpful. We have some legacy code where we have a lot of |
Pasting comment from similar issue:
(EDIT: I was reminded that it does have a few other non-whitespace changes it's willing to make, so I made this point a little too strongly.) |
+1 to what @kevinb9n said :) FWIW we have an Error Prone check for missing braces that can be run as a refactoring, which we use internally to help enforce that style rule. There are a handful of other cleanups like this that we may eventually be added to the formatter, but so far it hasn't been a priority, vs. focusing on pure whitespace reformatting changes that don't add or reorder tokens. |
@cushon , https://google.github.io/styleguide/javaguide.html#s4.1.1-braces-always-used
is it possible to get clarity on if yes, it would be awesome to update style guide and close this holly war. |
Braces are required for
Braces are not required for lambda expressions, so both of the following are allowed:
@romani is that helpful? As far as this relates to google-java-format, the formatter output will always follow Style Guide rules about whitespace (including breaking lines and indentation). There are other style guide rules that are out of scope for the formatter to fix, including e.g. the rules about names. |
ok, thanks a lot !! we just need to wait for sombody to fix this behavior in formatter. Checkstyle is violating |
To correct any violation of https://google.github.io/styleguide/javaguide.html#s4.1.1-braces-always-used
Currently it looks like a code that is formatted like
would be formatted (after running the tool) as:
where as I would expect it to be formatted as:
The text was updated successfully, but these errors were encountered: