[Improvement] Add line length check (100 chars) to Spotless configuration
- Dominant language
- Java
- Stars
- 3.2k
- Forks
- 935
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 298
Description
### What would you like to be improved?
Currently, the Spotless configuration uses Google Java Format for code formatting, but it does **not enforce the 100-character line length limit** specified in the Google Java Style Guide.
This was discovered during PR review ([#9824](https://github.com/apache/gravitino/pull/9824#discussion_r2747481313)) where a line exceeded 100 characters but passed `spotlessCheck`.
**Root Cause:**
Google Java Format (used by Spotless) handles code formatting like indentation and whitespace, but it does not automatically split long string literals or enforce line length limits. This means:
- `./gradlew build` passes even when lines exceed 100 characters
- Line length violations can only be caught during manual code review
### How should we improve?
Add a custom Spotless step to enforce the 100-character line length limit:
```kotlin
custom("Enforce line length limit (100 chars)") { fileContent ->
val maxLineLength = 100
val lines = fileContent.split("\n")
val violations = mutableListOf()
lines.forEachIndexed { index, line ->
val trimmedLine = line.trimEnd('\r')
if (trimmedLine.length > maxLineLength) {
violations.add("Line \${index + 1}: \${trimmedLine.length} chars (max \$maxLineLength)")
}
}
if (violations.isNotEmpty()) {
throw AssertionError(
"Lines exceed \$maxLineLength characters:\n \${violations.joinToString("\n ")}"
)
}
fileContent
}
```
Use `ratchetFrom('origin/main')` to only check changed files, allowing gradual adoption without breaking existing code.
**References:**
- Google Java Style Guide: https://google.github.io/styleguide/javaguide.html#s4.4-column-limit
- Spotless custom steps: https://github.com/diffplug/spotless/tree/main/plugin-gradle#custom-steps
Contributor guide
Assessment
This issue has not been assessed yet.