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

Spotless formatting #2524

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion gson/src/main/java/com/google/gson/Gson.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLongArray;

// Temporary unused import
import java.math.RoundingMode;

MaicolAntali marked this conversation as resolved.
Show resolved Hide resolved
/**
* This is the main class for using Gson. Gson is typically used by first constructing a
* Gson instance and then invoking {@link #toJson(Object)} or {@link #fromJson(String, Class)}
Expand Down Expand Up @@ -147,7 +150,13 @@
* @author Joel Leitch
* @author Jesse Wilson
*/
public final class Gson {

// Temporary formatting issue
public
final
class Gson

{
MaicolAntali marked this conversation as resolved.
Show resolved Hide resolved
static final boolean DEFAULT_JSON_NON_EXECUTABLE = false;
// Strictness of `null` is the legacy mode where some Gson APIs are always lenient
static final Strictness DEFAULT_STRICTNESS = null;
Expand Down
44 changes: 44 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@
<artifactId>truth</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.40.0</version>
</dependency>
MaicolAntali marked this conversation as resolved.
Show resolved Hide resolved
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -124,6 +129,45 @@
</execution>
</executions>
</plugin>
<!-- Spotless plugin: keeps the code formatted following the google-java-styleguide -->
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.40.0</version>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<configuration>
<formats>
<format>
<includes>
<include>*.md</include>
<include>.gitignore</include>
</includes>
<trimTrailingWhitespace/>
<endWithNewline/>
<indent>
<spaces>true</spaces>
<spacesPerTab>4</spacesPerTab>
</indent>
</format>
</formats>
Comment on lines +140 to +153
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this <formats> section needed? If I understand it correctly that would only apply to *.md and .gitignore the way it is currently configured; and I am not sure if we should impose any formatting rules on them.

Copy link
Contributor Author

@MaicolAntali MaicolAntali Nov 6, 2023

Choose a reason for hiding this comment

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

Formatting rules are very weak on.md and .gitignore. They replace tab characters with 4 spaces and trim trailing whitespace.

I think they are good general rules, but if you prefer to remove them, let me know.

Copy link
Collaborator

@Marcono1234 Marcono1234 Nov 6, 2023

Choose a reason for hiding this comment

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

Ok, I just asked because this section looked like the section from the Spotless examples and it isn't needed for Java formatting.

The combination of *.md with trimTrailingWhitespace should be removed though because they can break Markdown formatting. Arguably the Spotless examples are also flawed (diffplug/spotless#1877).

Edit: Nevermind, if the Markdown files are consistently using a trailing \ instead of two spaces for a hard line break, then it should be fine to remove trailing whitespace. But it might be good to add a comment here mentioning that a trailing \ can be used instead of trailing whitespace in Markdown files.

<java>
<googleJavaFormat>
<style>GOOGLE</style>
<reflowLongStrings>true</reflowLongStrings>
<formatJavadoc>true</formatJavadoc>
</googleJavaFormat>
<importOrder />
<removeUnusedImports />
<formatAnnotations /> <!-- Puts type annotations immediately before types. -->.
</java>
</configuration>
</plugin>
</plugins>

<pluginManagement>
Expand Down
Loading