Skip to content

Commit

Permalink
Switch to Google Java Format and configure Spotless auto-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
capoz authored and JorenHannes committed Jan 18, 2024
1 parent e0db171 commit 0066c50
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
23 changes: 8 additions & 15 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,15 @@ of the [Google Developer Documentation Style
Guide](https://developers.google.com/style/).
## Code format
We follow the [Google Java Code Style](https://google.github.io/styleguide/javaguide.html). The code should be
auto-formatted before any pull request by running:
```
./gradlew spotlessApply
```
We strive for code that is super-aligned. Ideally, the code should look like a
set of tables, for variable declarations, parameter declarations, ternary
operators, etc.
- The basic indentation is 4 spaces (never tabs).
- Curly braces are on separate lines.
- The ideal maximum line length is 120 characters. Documentation and comments
should stick to this limit. Code that has a nice table-like structure can
exceed it.
In particular some elements of the code style are not covered by Spotless and particular attention should be
given to them:
- Imports of multiple classes in the same package are declared explicitly, **no wildcard imports**.
Expand All @@ -183,10 +180,6 @@ operators, etc.
- Whenever overriding a method, add the @Override annotation.
In practice, an IDE can help to obtain a clean indentation and structure, but
it is often not sufficient. Be careful to never upset a cleanly formatted
source file by automatically reformatting it.
### Naming Conventions
- Names (class names, field names, etc) should be descriptive.
Expand Down
6 changes: 6 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id 'jacoco'
id "org.jlleitschuh.gradle.ktlint"
id "org.sonarqube"
id 'com.diffplug.spotless'
}

dependencies {
Expand Down Expand Up @@ -97,3 +98,8 @@ if (hasProperty('PROGUARD_SIGNING_KEY')) {
}
}

spotless {
java {
googleJavaFormat()
}
}
7 changes: 7 additions & 0 deletions base/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id 'jacoco'
id "org.jlleitschuh.gradle.ktlint"
id "java-test-fixtures"
id 'com.diffplug.spotless'
}

dependencies {
Expand Down Expand Up @@ -153,3 +154,9 @@ if (hasProperty('PROGUARD_SIGNING_KEY')) {
sign publishing.publications
}
}

spotless {
java {
googleJavaFormat()
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ plugins {
id "org.sonarqube" version "3.4.0.2513"
id "io.freefair.aggregate-javadoc" version "6.5.0.3"
id "org.jlleitschuh.gradle.ktlint" version "10.3.0" apply false
id "com.diffplug.spotless" version "6.13.0"
}

allprojects {
Expand Down
11 changes: 11 additions & 0 deletions docs/md/releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@
- Add `IdentifiedArrayReferenceValue.generalize()` to maintain `ID` when applied to two instances with same `ID`.
- Improve `ExecutingInvocationUnit` support to methods that transform a `String` into an array of a primitive type.

## New Code Style

We have changed our code style to follow the Google Java Style Guide. A new auto-formatter is now available to make contributing to
ProGuardCORE easier:

```
./gradlew spotlessApply
```

More information can be found in the `Code Style` section in `CONTRIBUTING.md`.

## Version 9.1

### Improved
Expand Down
7 changes: 7 additions & 0 deletions tools/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'maven-publish'
id 'signing'
id "org.jlleitschuh.gradle.ktlint"
id 'com.diffplug.spotless'
}

dependencies {
Expand Down Expand Up @@ -78,3 +79,9 @@ if (hasProperty('PROGUARD_SIGNING_KEY')) {
sign publishing.publications
}
}

spotless {
java {
googleJavaFormat()
}
}

0 comments on commit 0066c50

Please sign in to comment.