-
Notifications
You must be signed in to change notification settings - Fork 850
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
Java code formatter #863
Comments
They are still using Checkstyle to check the coding style. ./gradlew check However, Checkstyle did not seem to have an autofix feature. I tried to use this plugin, but I couldn't figure out where the syntax error was. I tried this. diff --git a/build.gradle b/build.gradle
index 249b1a49..019af96d 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,6 +8,7 @@ plugins {
id 'distribution'
id 'checkstyle'
id 'com.github.spotbugs' version "4.6.2"
+ id "com.diffplug.spotless" version "5.12.1"
}
tasks.withType(JavaCompile) {
@@ -25,6 +26,12 @@ repositories {
mavenCentral()
}
+spotless {
+ java {
+ googleJavaFormat('1.7').aosp()
+ }
+}
+
sourceSets {
main {
java { # check
$ ./gradlew spotlessCheck
# autofix
$ ./gradlew spotlessApply There was a very large amount of revision. |
As you figured out, checkstyle is already in the build but except for some very obvious rules it's mostly turned off. It's no issue at all to adjust the checkstyle rules to enforce more things, or to replace it with another formatter. The problem is that adopting any formatter would introduce a multi-thousand-line set of changes to the codebase. Everyone who has an outstanding PR, or a branch with a bit of experimental things, or a fork of Rhino, would have a messy merge on their hands. I can think of a few ways to make this less painful:
But I have held off on doing anything like this because of the aforementioned merge problems. If there were some code formatter out there that we could annotate with "already fixed" or something so that it'd only complain about certain files, then perhaps that would be another way. |
At least in teamcity there is a way to have some kind of dynamic threshold like ,The number of warnings of a build has to be <= the number of warnings from the previous build run'. Maybe enabling something like this for the ci build might be a way into a future with more consistent formatting.
Personally i do not like this huge reformat steps, having clear rules and applying these rule for the code we change over the time is fine for me.
|
If you have the auto-formatting feature, you can simply run the command to remove the error. |
This may not be as bad as I had feared, since spotless has the "ratchet" feature. Check out #866 and if you like it we'll do it! |
Fine for me +1 |
Thanks! |
I would like a code formatter to unify coding styles.
./gradlew format
)Is this a good idea to use?
https://github.com/sherter/google-java-format-gradle-plugin
The text was updated successfully, but these errors were encountered: