lint/strict/java
Analyzer findings fail the build
Implements lint/strict for java.
| Severity | warning |
| Tiers | 1, 2 |
| Stacks | java |
| Scope | each |
| Kind | expr |
| Source | library v0.3.1 |
| Selected by | fleetlint-recommended@v0.3.1 |
Requirement
No analyzer in the build is set to let findings pass (failOnViolation, failsOnError or failOnError false, ignoreFailures = true), and Checkstyle, when used, fails on warnings too: its configuration sets severity error, violationSeverity is warning, or Gradle’s maxWarnings is 0.
Why
An analyzer whose findings only print is skipped by everyone; Checkstyle’s defaults report most checks as warnings that do not fail the build.
Applies when
(["", "../", "../../", "../../../"].map(d, [d + "pom.xml", d + "build.gradle", d + "build.gradle.kts"]).flatten()
+ glob("buildSrc/**/*.gradle*") + glob("build-logic/**/*.gradle*"))
.exists(f, file(f) && text(f).matches("(?m)maven-checkstyle-plugin|[\"']checkstyle[\"']|^\\s*checkstyle\\s*(\\{|$)|error_prone_core|net\\.ltgt\\.errorprone|spotbugs-maven-plugin|com\\.github\\.spotbugs|maven-pmd-plugin|[\"']pmd[\"']|^\\s*pmd\\s*(\\{|$)"))Check
[(["", "../", "../../", "../../../"].map(d, [d + "pom.xml", d + "build.gradle", d + "build.gradle.kts"]).flatten()
+ glob("buildSrc/**/*.gradle*") + glob("build-logic/**/*.gradle*")).filter(f, file(f))]
.exists(b,
!b.exists(f, text(f).matches("(?i)<(failOnViolation|failsOnError|failOnError)>\\s*false\\s*<|ignoreFailures\\s*=\\s*true"))
&& (!b.exists(f, text(f).matches("(?m)maven-checkstyle-plugin|[\"']checkstyle[\"']|^\\s*checkstyle\\s*(\\{|$)"))
|| b.exists(f, text(f).matches("<violationSeverity>\\s*warning\\s*<|maxWarnings\\s*=\\s*0\\b"))
|| (glob("**/checkstyle*.xml") + ["../", "../../", "../../../"].map(d, d + "config/checkstyle/checkstyle.xml").filter(f, file(f)))
.exists(f, text(f).matches("name=\"severity\"\\s+value=\"error\""))))Fix
Remove the settings that ignore failures and set Checkstyle’s severity to error; fleetlint fix --apply writes config/checkstyle/checkstyle.xml with severity error when it is missing (Gradle’s default location; Maven needs configLocation pointing at it).
Agent instruction: Remove failOnViolation/failOnError false and ignoreFailures true from the build, make Checkstyle fail on warnings (severity error in its configuration), and fix what then fails.
fleetlint fix can apply this rule’s fix automatically (1 action(s)).
See: https://fleetlint.org/baseline/#static-analysis, https://fleetlint.org/stacks/#java
Generated by fleetlint docs from catalog v0.3.1.