Skip to content

ci: set up Spotless linting in CI (#351)#366

Open
KaleabArgaw wants to merge 1 commit intodocling-project:mainfrom
KaleabArgaw:ci/351-code-linting
Open

ci: set up Spotless linting in CI (#351)#366
KaleabArgaw wants to merge 1 commit intodocling-project:mainfrom
KaleabArgaw:ci/351-code-linting

Conversation

@KaleabArgaw
Copy link

@KaleabArgaw KaleabArgaw commented Feb 25, 2026

Fixes #351

@edeandrea
Copy link
Contributor

Thanks @KaleabArgaw for this! I'll give it a look through later today or tomorrow!

I am going to have copilot do an automated review of it too, but please don't take any actions yet based on what it says. I'm really just testing it out to see if I trust it or not :)

@edeandrea
Copy link
Contributor

@all-contributors add @KaleabArgaw for code documentation

@allcontributors
Copy link
Contributor

@edeandrea

I've put up a pull request to add @KaleabArgaw! 🎉

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR integrates Spotless code linting into the CI pipeline to enforce consistent code formatting across the Java codebase. The implementation uses an incremental rollout strategy via ratchetFrom("origin/main"), which checks only files changed from the main branch. This allows for gradual adoption without requiring all existing code to be reformatted immediately.

Changes:

  • Adds Spotless Gradle plugin (version 7.2.1) to the project dependencies
  • Configures Spotless in the shared Java convention plugin with basic formatting rules (remove unused imports, format annotations, trim trailing whitespace, end with newline)
  • Adds a new lint CI job that runs Spotless formatting checks on all pull requests
  • Updates CONTRIBUTING.md with instructions for running Spotless locally

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
gradle/libs.versions.toml Adds Spotless version (7.2.1) and plugin dependency declaration to the version catalog
buildSrc/build.gradle.kts Adds Spotless Gradle plugin as a buildSrc dependency, making it available to convention plugins
buildSrc/src/main/kotlin/docling-java-shared.gradle.kts Applies Spotless plugin and configures it with ratchetFrom strategy and basic Java formatting rules
.github/workflows/build.yml Adds new lint job that checks out code with full history (fetch-depth: 0), runs spotlessApply, and verifies no formatting changes are needed
CONTRIBUTING.md Documents new Spotless commands (spotlessCheck and spotlessApply) for contributors

@github-actions
Copy link

:java_duke: JaCoCo coverage report

Overall Project 46.08% 🔴

There is no coverage information present for the Files changed

@github-actions
Copy link

github-actions bot commented Feb 25, 2026

TestsPassed ✅SkippedFailed
Gradle Test Results (all modules & JDKs)936 ran936 passed0 skipped0 failed
TestResult
No test annotations available

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

Copy link
Contributor

@edeandrea edeandrea left a comment

Choose a reason for hiding this comment

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

See comments in-line.

I'd also like @ThomasVitale to take a look.


spotless {
// Roll out linting incrementally by checking only files changed from main.
ratchetFrom("origin/main")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is causing a build failure in the docs module that needs to be investigated.

trimTrailingWhitespace()
endWithNewline()
}
}
Copy link
Contributor

@edeandrea edeandrea Feb 25, 2026

Choose a reason for hiding this comment

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

I haven't read up on spotless and its configuration - is there a way to specify the configuration outside of the gradle dsl? And is there a way to get it to respect what we have in .editorconfig?

Ideally I'd prefer control over formatting/etc to be defined in a single place, whether thats .editorconfig or somewhere else. It would also be nice if when a user loads the project into an IDE, the formatting rules are respected by the IDE. Anything we can do to make that easier is a win.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah we can govern it using .editorconfig

Copy link
Contributor

@edeandrea edeandrea Feb 26, 2026

Choose a reason for hiding this comment

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

Does it use .editorconfig by default if you don't add any additional config for java?

I see in the documentation it works that way for kotlin (ktlint)

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@KaleabArgaw KaleabArgaw force-pushed the ci/351-code-linting branch 2 times, most recently from feb364e to ad6b1db Compare February 26, 2026 15:05
@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

@edeandrea
Copy link
Contributor

Hi @KaleabArgaw thank you so much for this!

I've just downloaded & built this PR locally and purposefully introduced some things that should break the spotless check. When I run ./gradlew --no-daemon --console=plain spotlessCheck it doesn't seem to find any violations, even though I have introduced clear violations against things inside .editorconfig.

╰─ ./gradlew --no-daemon --console=plain clean spotlessCheck                   
To honour the JVM settings for this build a single-use Daemon process will be forked. For more on this, please refer to https://docs.gradle.org/9.3.1/userguide/gradle_daemon.html#sec:disabling_the_daemon in the Gradle documentation.
Daemon will be stopped at the end of the build 
> Task :buildSrc:checkKotlinGradlePluginConfigurationErrors SKIPPED
> Task :buildSrc:generateExternalPluginSpecBuilders UP-TO-DATE
> Task :buildSrc:extractPrecompiledScriptPluginPlugins UP-TO-DATE
> Task :buildSrc:compilePluginsBlocks UP-TO-DATE
> Task :buildSrc:generatePrecompiledScriptPluginAccessors UP-TO-DATE
> Task :buildSrc:generateScriptPluginAdapters UP-TO-DATE
> Task :buildSrc:compileKotlin UP-TO-DATE
> Task :buildSrc:compileJava NO-SOURCE
> Task :buildSrc:compileGroovy NO-SOURCE
> Task :buildSrc:pluginDescriptors UP-TO-DATE
> Task :buildSrc:processResources UP-TO-DATE
> Task :buildSrc:classes UP-TO-DATE
> Task :buildSrc:jar UP-TO-DATE
> Task :docling-core:clean
> Task :docling-serve-api:clean
> Task :docling-serve-client:clean
> Task :docling-testcontainers:clean
> Task :docling-version-tests:clean
> Task :docs:clean UP-TO-DATE
> Task :test-report-aggregation:clean UP-TO-DATE
> Task :spotlessInternalRegisterDependencies UP-TO-DATE
> Task :docling-core:spotlessJava
> Task :docling-core:spotlessJavaCheck
> Task :docling-core:spotlessCheck
> Task :docling-serve-api:spotlessJava
> Task :docling-serve-api:spotlessJavaCheck
> Task :docling-serve-api:spotlessCheck
> Task :docling-serve-client:spotlessJava
> Task :docling-serve-client:spotlessJavaCheck
> Task :docling-serve-client:spotlessCheck
> Task :docling-testcontainers:spotlessJava
> Task :docling-testcontainers:spotlessJavaCheck
> Task :docling-testcontainers:spotlessCheck
> Task :docling-version-tests:spotlessJava
> Task :docling-version-tests:spotlessJavaCheck
> Task :docling-version-tests:spotlessCheck

)

Signed-off-by: Kaleab Argaw <kaleruha16@gmail.com>
@KaleabArgaw
Copy link
Author

Hey @edeandrea i removed the on build fail that's why you can check now locally.

@github-actions
Copy link

HTML test reports are available as workflow artifacts (zipped HTML).

• Download: Artifacts for this run

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.

Set up code linting as part of DevOps processes

3 participants