Skip to content

Commit

Permalink
chore: Add Taskfile tasks to lint Java files and apply rules to exist…
Browse files Browse the repository at this point in the history
…ing files. (#7)
  • Loading branch information
kirkrodrigues authored Oct 30, 2024
1 parent 29ba113 commit 2e61c59
Show file tree
Hide file tree
Showing 6 changed files with 492 additions and 5 deletions.
404 changes: 404 additions & 0 deletions .eclipse-formatter.xml

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,21 @@ To run all linting checks AND automatically fix any fixable issues:
task lint:fix
```

### Running specific linters
The commands above run all linting checks, but for performance you may want to run a subset (e.g.,
if you only changed Java files, you don't need to run the YAML linting checks) using one of the
tasks in the table below.

| Task | Description |
|--------------------------|-----------------------------------------------------------|
| `lint:java-check` | Runs the Java linters (formatters and static analyzers). |
| `lint:java-fix` | Runs the Java linters and fixes some violations. |
| `lint:java-format-check` | Runs the Java formatters. |
| `lint:java-format-fix` | Runs the Java formatters and fixes some violations. |
| `lint:java-static-check` | Runs the Java static analyzers. |
| `lint:java-static-fix` | Runs the Java static analyzers and fixes some violations. |
| `lint:yml-check` | Runs the YAML linters. |
| `lint:yml-fix` | Runs the YAML linters and fixes some violations. |

[log4j2]: https://logging.apache.org/log4j/2.x/index.html
[Task]: https://taskfile.dev
26 changes: 26 additions & 0 deletions lint-tasks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,38 @@ vars:
tasks:
check:
cmds:
- task: "java-check"
- task: "yml-check"

fix:
cmds:
- task: "java-fix"
- task: "yml-fix"

java-check:
cmds:
- task: "java-format-check"
- task: "java-static-check"

java-fix:
cmds:
- task: "java-format-fix"
- task: "java-static-fix"

java-format-check:
deps: ["venv"]
cmd: "mvn spotless:check"

java-format-fix:
deps: ["venv"]
cmd: "mvn spotless:apply"

java-static-check:
# Alias task to `java-static-fix` since we don't currently support automatic fixes.
aliases: ["java-static-fix"]
deps: ["venv"]
cmd: "mvn compile spotbugs:check"

yml:
aliases:
- "yml-check"
Expand Down
43 changes: 43 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
<pluginManagement>
<!-- Lock plugins versions to avoid using Maven defaults -->
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
</plugin>
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<version>4.8.6.5</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
Expand Down Expand Up @@ -154,6 +164,15 @@
lifecycle phases. -->

<!-- No phase -->
<plugin>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-maven-plugin</artifactId>
<configuration>
<effort>Max</effort>
<includeTests>true</includeTests>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
Expand All @@ -163,6 +182,30 @@
</plugin>

<!-- phase:validate -->
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<configuration>
<java>
<cleanthat/>
<eclipse>
<file>.eclipse-formatter.xml</file>
</eclipse>
<importOrder>
<order>java|javax,,com.yscope.logging.log4j2</order>
</importOrder>
<removeUnusedImports/>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/yscope/logging/log4j2/Boilerplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ public class Boilerplate {
/**
* @return A boilerplate greeting.
*/
public static String getGreeting() {
return "Hello, world!";
}
public static String getGreeting() { return "Hello, world!"; }
}
4 changes: 2 additions & 2 deletions src/test/java/com/yscope/logging/log4j2/BoilerplateTests.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.yscope.logging.log4j2;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

public class BoilerplateTests {
@Test
public void testGreeting() {
Expand Down

0 comments on commit 2e61c59

Please sign in to comment.