Skip to content

ci: check the Java formatting and lint - #111

Merged
uniqueg merged 3 commits into
devfrom
ci/java-lint
Nov 7, 2026
Merged

uniqueg merged 3 commits into
devfrom
ci/java-lint

Conversation

@uniqueg

@uniqueg uniqueg commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

Summary

This is the third of three PRs for #85, after #109 (formatting only) and #110 (.git-blame-ignore-revs).

  • Braces. Single-statement if/for/while blocks in the hand-written code now have braces, so Checkstyle's NeedBraces passes. One loop in ExecutorCommandWrapper modified its loop variable. It now works on a local copy, with the same behaviour.
  • Lint config. pom.xml adds spotless-maven-plugin 2.30.0 (google-java-format 1.7, AOSP style, plus removing unused imports) and maven-checkstyle-plugin 3.3.1 with Checkstyle 9.3. These are the last versions that run on Java 8.
    • checkstyle.xml holds 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.
    • Both tools skip the generated files listed in src/main/java/.openapi-generator/FILES. Checkstyle does this through a filter anchored to src/main/java, so tests in the same packages are still checked.
    • Neither tool is bound to a lifecycle phase. ./mvnw verify and the image build don't change.
  • CI. The Lint job runs ./mvnw -B spotless:check checkstyle:check on Temurin 8. It has no Maven cache, so it can't fill the Test job's cache key with only the lint plugins.
  • Docs. docs/development.md gets a new "Formatting and linting" section: tools, commands, versions, and git config blame.ignoreRevsFile. The CI paragraph is updated too.

Closes #85

Verification

  • ./mvnw spotless:check checkstyle:check: passes with no violations.
  • ./mvnw clean verify on Temurin 8: passes. That covers all unit tests and the 53 integration tests, plus the JaCoCo coverage check.
  • I added an unbraced if to 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.
  • On the branch before the review fixes, javap -c -p dumps of all classes match those of style: format the Java code #109 except ExecutorCommandWrapper, which is the loop variable change above. Braces don't change bytecode.
  • mkdocs build --strict: passes.
  • After the Sourcery finding, the generated files are excluded by exact name, not by the prefixes Service*/Tes*. A new hand-written tes/model/TesProbe.java with an unbraced if is reported by both spotless:check and checkstyle:check.
  • CI on bc7f73f: the gate CI passed and every job pass, including Lint. codecov/patch (not required) fails at 50.79%: the brace-only lines sit in existing code that has no tests. codecov/project passes (-0.11 points, from the changed line count).

Review

Full review: two rounds of adversarial-reviewer and quality-reviewer. Fixed findings:

  • Checkstyle excludes that also skipped a hand-written test.
  • Docs that pointed to .git-blame-ignore-revs before build: ignore the reformat in git blame #110 added it.
  • A Maven cache key shared with Test.
  • A stale CI comment.
  • Notes on Java 8, wildcard imports and verify.

Declined review findings

  • The generated-file list lives in 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.
  • Patch coverage below 100% (Codecov). The uncovered lines are braces added around existing untested statements. Testing those code paths is out of scope for a lint PR.

🤖 Generated with Claude Code

uniqueg and others added 2 commits November 7, 2026 17:54
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]>
@sourcery-ai

sourcery-ai Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Brace the existing single-statement control-flow blocks and use a local copy of the loop variable in ExecutorCommandWrapper, preserving behavior while satisfying the new lint rules.

  • src/main/java/uk/ac/ebi/tsc/tesk/config/security/User.java L70-72, L219-258
  • src/main/java/uk/ac/ebi/tsc/tesk/config/swagger/OAuth2ClientProperties.java L84-86
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/ExecutorCommandWrapper.java L42-49
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskStateResolver.java L85-96 (+4 small edits)
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskmasterEnvProperties.java L113-115, L120-122
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/TesKubernetesConverter.java L317-319
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/Job.java L46-48, L56-58
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/Task.java L75-77
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/convert/data/TaskListStrategy.java L49-51
  • src/main/java/uk/ac/ebi/tsc/tesk/k8s/service/KubernetesClientWrapper.java L84-91, L148-157
  • src/main/java/uk/ac/ebi/tsc/tesk/tes/service/TesServiceImpl.java L130-132, L137-139

Configuration

Define the bug-oriented Checkstyle rules and generated-source suppression, then configure Spotless and Checkstyle Maven plugins with matching generated-file exclusions.

  • checkstyle.xml L1-45
  • pom.xml L391-461

Add Java 8 setup and run the formatting and lint checks in the CI Lint job without introducing a Maven cache.

  • .github/workflows/ci.yml L74 (removed lines), L88-97

Documentation

Document the formatting and lint tools, commands, generated-file exclusions, Java version constraints, blame configuration, and updated CI checks.

  • docs/development.md L50-83, L102-105

Tests

Add braces to test control flow to keep the tests compliant with the new formatting and lint checks.

  • src/test/java/uk/ac/ebi/tsc/tesk/k8s/convert/TaskStateResolverTest.java L224-226, L384-392

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.79365% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.05%. Comparing base (2c5bbb7) to head (bc7f73f).

Files with missing lines Patch % Lines
.../java/uk/ac/ebi/tsc/tesk/config/security/User.java 0.00% 9 Missing and 10 partials ⚠️
.../tsc/tesk/k8s/convert/TaskmasterEnvProperties.java 0.00% 2 Missing and 2 partials ⚠️
.../tsc/tesk/k8s/service/KubernetesClientWrapper.java 33.33% 2 Missing and 2 partials ⚠️
...sc/tesk/config/swagger/OAuth2ClientProperties.java 0.00% 1 Missing and 1 partial ⚠️
.../java/uk/ac/ebi/tsc/tesk/k8s/convert/data/Job.java 50.00% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review November 7, 2026 17:01

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread pom.xml Resolved
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]>

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sourcery assessment

Approved.

@uniqueg
uniqueg merged commit 31b69d9 into dev Nov 7, 2026
33 of 34 checks passed
@uniqueg
uniqueg deleted the ci/java-lint branch November 7, 2026 17:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ci: lint and format the Java code

1 participant