Repository navigation
ci: check the Java formatting and lint - #111
Conversation
Add braces to the if and for statements without them, and stop reassigning the loop variable in ExecutorCommandWrapper, as the Checkstyle rules of the next commit require. Apart from the local variable in ExecutorCommandWrapper, the bytecode is unchanged. Refs #85 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Add Spotless (google-java-format 1.7, AOSP style) and Checkstyle 9.3 (checkstyle.xml) to pom.xml, both excluding the generated files, and run their checks in the Lint job on Java 8. Document how to format and check the code. Closes #85 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideImplementationBrace the existing single-statement control-flow blocks and use a local copy of the loop variable in
ConfigurationDefine the bug-oriented Checkstyle rules and generated-source suppression, then configure Spotless and Checkstyle Maven plugins with matching generated-file exclusions.
Add Java 8 setup and run the formatting and lint checks in the CI Lint job without introducing a Maven cache.
DocumentationDocument the formatting and lint tools, commands, generated-file exclusions, Java version constraints, blame configuration, and updated CI checks.
TestsAdd braces to test control flow to keep the tests compliant with the new formatting and lint checks.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## dev #111 +/- ##
==========================================
- Coverage 62.16% 62.05% -0.11%
==========================================
Files 64 64
Lines 2471 2496 +25
Branches 257 257
==========================================
+ Hits 1536 1549 +13
- Misses 794 806 +12
Partials 141 141 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pom.xml" line_range="411-412" />
<code_context>
+ <exclude>src/main/java/uk/ac/ebi/tsc/tesk/tes/api/ApiUtil.java</exclude>
+ <exclude>src/main/java/uk/ac/ebi/tsc/tesk/tes/api/ServiceInfoApi.java</exclude>
+ <exclude>src/main/java/uk/ac/ebi/tsc/tesk/tes/api/TasksApi.java</exclude>
+ <exclude>src/main/java/uk/ac/ebi/tsc/tesk/tes/model/Service*.java</exclude>
+ <exclude>src/main/java/uk/ac/ebi/tsc/tesk/tes/model/Tes*.java</exclude>
+ </excludes>
+ <googleJavaFormat>
</code_context>
<issue_to_address>
**New handwritten models evade lint**
When a handwritten model is added under this package with a `Service` or `Tes` prefix, spotless and Checkstyle exclude model files by `Service`/`Tes` filename prefix rather than by the generated-file manifest, so a new handwritten model with either prefix is skipped by both checks and can enter the codebase without formatting or lint enforcement.
Exclude only the files listed in the generated-file manifest, or add a check that fails when the exclusion patterns cover files not listed there.
Also at `checkstyle.xml:19`.
</issue_to_address>Linked issues
#85 ci: lint and format the Java code · 2 of 2 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Run a Java formatter and linter in the Lint job and document them in the developer docs. | ✅ Met | Spotless and Checkstyle are configured in pom.xml, run by the Lint job, and described in docs/development.md. |
| 2 | Exclude or otherwise handle generated code. | ✅ Met | The generated files listed in src/main/java/.openapi-generator/FILES are excluded from Spotless and suppressed in Checkstyle. |
Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: pom.xml:412
List the generated files from .openapi-generator/FILES by name in the Spotless excludes and the Checkstyle filter, instead of the prefixes Service* and Tes*, so a new hand-written model with such a name is still formatted and linted. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
This is the third of three PRs for #85, after #109 (formatting only) and #110 (
.git-blame-ignore-revs).if/for/whileblocks in the hand-written code now have braces, so Checkstyle'sNeedBracespasses. One loop inExecutorCommandWrappermodified its loop variable. It now works on a local copy, with the same behaviour.pom.xmladdsspotless-maven-plugin2.30.0 (google-java-format 1.7, AOSP style, plus removing unused imports) andmaven-checkstyle-plugin3.3.1 with Checkstyle 9.3. These are the last versions that run on Java 8.checkstyle.xmlholds bug-oriented rules only and leaves layout to the formatter: braces,equals/hashCode, fall-through, empty statements and catch blocks, unused imports and the like.src/main/java/.openapi-generator/FILES. Checkstyle does this through a filter anchored tosrc/main/java, so tests in the same packages are still checked../mvnw verifyand the image build don't change.Lintjob runs./mvnw -B spotless:check checkstyle:checkon Temurin 8. It has no Maven cache, so it can't fill theTestjob's cache key with only the lint plugins.docs/development.mdgets a new "Formatting and linting" section: tools, commands, versions, andgit config blame.ignoreRevsFile. The CI paragraph is updated too.Closes #85
Verification
./mvnw spotless:check checkstyle:check: passes with no violations../mvnw clean verifyon Temurin 8: passes. That covers all unit tests and the 53 integration tests, plus the JaCoCo coverage check.ifto a hand-written test (tes/model/TesResourcesTest.java) and to a generated model (tes/model/TesTask.java). Checkstyle reported the test and skipped the generated file.javap -c -pdumps of all classes match those of style: format the Java code #109 exceptExecutorCommandWrapper, which is the loop variable change above. Braces don't change bytecode.mkdocs build --strict: passes.Service*/Tes*. A new hand-writtentes/model/TesProbe.javawith an unbracedifis reported by bothspotless:checkandcheckstyle:check.CI passedand every job pass, includingLint.codecov/patch(not required) fails at 50.79%: the brace-only lines sit in existing code that has no tests.codecov/projectpasses (-0.11 points, from the changed line count).Review
Full review: two rounds of
adversarial-reviewerandquality-reviewer. Fixed findings:.git-blame-ignore-revsbefore build: ignore the reformat in git blame #110 added it.Test.verify.Declined review findings
FILES, the Spotless excludes and the Checkstyle filter (low). "Keep in sync" comments link the two configs. A stale list shows up in CI, because Spotless would fail on generated code it newly formats.🤖 Generated with Claude Code