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

Introduce automated code formatting #866

Merged
merged 1 commit into from
Apr 15, 2021
Merged

Introduce automated code formatting #866

merged 1 commit into from
Apr 15, 2021

Conversation

gbrail
Copy link
Collaborator

@gbrail gbrail commented Apr 15, 2021

This PR uses google-java-format, via the "spotless" plugin, to format
the Java code.

It uses the "ratchet" mode of Spotless. That means that all Java
code committed AFTER this commit will be required to be formatted
using google-java-format. This will let us reformat the codebase
gradually rather than in one huge chunk.

We are keeping "checkstyle" as it checks for a few other things like
"star imports" that we'd still like to avoid.

This PR uses google-java-format, via the "spotless" plugin, to format
the Java code.

It uses the "ratched" mode of Spotless. That means that all Java
code committed AFTER this commit will be required to be formatted
using google-java-format. This will let us reformat the codebase
gradually rather than in one huge chunk.

We are keeping "checkstyle" as it checks for a few other things like
"star imports" that we'd still like to avoid.
@gbrail gbrail mentioned this pull request Apr 15, 2021
spotless {
ratchetFrom 'code-formatting-required'
java {
googleJavaFormat().aosp()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the coding style ok with Android Open Source Project (AOSP) style?
https://source.android.com/setup/contribute/code-style

You can also change to the Google Java Style Guide.
https://google.github.io/styleguide/javaguide.html

I chose AOSP because the style over here had 4 spaces indentations.
This way, you can also change the indentation in the Google Java Style Guide. However, it failed to change some of the files.

spotless {
    ratchetFrom 'code-formatting-required'
    java {
        googleJavaFormat()
        indentWithTabs(2)
        indentWithSpaces(4)
    }
}

@gbrail
Copy link
Collaborator Author

gbrail commented Apr 15, 2021

I don't think that those other options to spotless are actually passed to google-java-format -- I think that they do something else.

I picked AOSP because it looks like most of the old Rhino code uses four spaces for indents instead of two. (I would prefer two if this code was new.)

I search quickly through the source for google-java-format and the only difference I could see for AOSP was the way that it sorts import statements -- I think that everything else is the same.

@tuchida
Copy link
Contributor

tuchida commented Apr 15, 2021

OK. Thank you.

@gbrail gbrail merged commit b4074d6 into master Apr 15, 2021
@gbrail gbrail deleted the greg-spotless branch April 15, 2021 23:41
@p-bakker p-bakker added this to the Release 1.7.14 milestone Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants