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

If condition with single line fails google_checks.xml #301

Closed
fzakaria opened this issue Aug 6, 2018 · 1 comment
Closed

If condition with single line fails google_checks.xml #301

fzakaria opened this issue Aug 6, 2018 · 1 comment

Comments

@fzakaria
Copy link

fzakaria commented Aug 6, 2018

I ran the latest google-java-format on my codebase and it formatted the code as follows:

  @Override
  public boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;
    MethodAndPattern that = (MethodAndPattern) o;
    return Objects.equals(method, that.method) && Objects.equals(pattern, that.pattern);
  }

The if-conditions on a single line are failing Google's Checkstyle checks https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml

Looking at the guide : https://google.github.io/styleguide/javaguide.html#s4.1-braces
It says:

Braces are used with if, else, for, do and while statements, even when the body is empty or contains only a single statement.

so I'm guessing the fix is in this project ?

I'm using 1.6 through Spotless:

            <!-- Spotless is a general-purpose formatting plugin. It is completely à la carte,
            but also includes powerful "batteries-included" if you opt-in
            https://github.com/diffplug/spotless/tree/master/plugin-maven -->
            <plugin>
                <groupId>com.diffplug.spotless</groupId>
                <artifactId>spotless-maven-plugin</artifactId>
                <version>${spotless.version}</version>
                <configuration>
                    <java>
                        <removeUnusedImports/>
                        <googleJavaFormat>
                            <version>1.6</version>
                            <!-- Optional, available versions: GOOGLE, AOSP
                            https://github.com/google/google-java-format/blob/master/core/src/main/java/com/google/googlejavaformat/java/JavaFormatterOptions.java -->
                            <style>GOOGLE</style>
                        </googleJavaFormat>
                    </java>
                </configuration>
            </plugin>
@fzakaria
Copy link
Author

fzakaria commented Aug 6, 2018

Nvm -- it's duplicate of #51

@fzakaria fzakaria closed this as completed Aug 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant