You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "mchades (via GitHub)" <gi...@apache.org> on 2026/01/31 04:09:00 UTC
[I] [Improvement] Add line length check (100 chars) to Spotless configuration [gravitino]
mchades opened a new issue, #9834:
URL: https://github.com/apache/gravitino/issues/9834
### Problem
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
### Proposed Solution
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<String>()
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
}
```
### Impact
Adding this rule will require fixing existing violations in the codebase. We should:
1. First run the check to identify all current violations
2. Fix existing violations (can be done incrementally using Spotless's `ratchetFrom` feature)
3. Enable the check for all new code
### Additional Context
- Google Java Style Guide: https://google.github.io/styleguide/javaguide.html#s4.4-column-limit
- Spotless custom steps documentation: https://github.com/diffplug/spotless/tree/main/plugin-gradle#custom-steps
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Improvement] Add line length check (100 chars) to Spotless configuration [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on issue #9834:
URL: https://github.com/apache/gravitino/issues/9834#issuecomment-4073251243
> If this is to be added as a generic step, the line length should be configurable.
Line length should not be changed if it is implemented as a project standard, so it is not necessary to make it configurable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Improvement] Add line length check (100 chars) to Spotless configuration [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades closed issue #9834: [Improvement] Add line length check (100 chars) to Spotless configuration
URL: https://github.com/apache/gravitino/issues/9834
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Improvement] Add line length check (100 chars) to Spotless configuration [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on issue #9834:
URL: https://github.com/apache/gravitino/issues/9834#issuecomment-6435514466
Deferring strict line-length enforcement for now. A blanket 100-character check would incorrectly flag Google Style exceptions such as long imports, text-block contents, and unbreakable Javadoc URLs, so it requires additional handling. Existing Spotless formatting remains in place. We can reopen this if long lines become a recurring review issue.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Improvement] Add line length check (100 chars) to Spotless configuration [gravitino]
Posted by "mchades (via GitHub)" <gi...@apache.org>.
mchades commented on issue #9834:
URL: https://github.com/apache/gravitino/issues/9834#issuecomment-3827492077
## Implementation Notes
After investigating this issue, here are the key findings and recommended solution:
### Problem Analysis
1. **Google Java Format doesn't enforce line length**: Spotless uses Google Java Format which handles code formatting (indentation, whitespace) but does **not** automatically split long string literals or enforce line length limits.
2. **Custom step needed**: We need to add a custom Spotless step to check line length:
```kotlin
custom("Enforce line length limit (100 chars)") { fileContent ->
val maxLineLength = 100
val lines = fileContent.split("\n")
val violations = mutableListOf<String>()
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
}
```
3. **Gradual adoption challenge**: There are **784 Java files** with lines exceeding 100 characters. Using `ratchetFrom('origin/main')` allows gradual adoption by only checking changed files.
4. **CI shallow clone issue**: GitHub Actions uses shallow clone, so `origin/main` reference doesn't exist, causing `ratchetFrom` to fail with `No such reference 'origin/main'`.
### Recommended Solution
Modify the CI workflow to fetch the main branch before running Spotless:
```yaml
- uses: actions/checkout@v4
- name: Fetch main branch for Spotless ratchet
run: git fetch origin main --depth=1
- name: Build
run: ./gradlew build
```
Alternatively, use `fetch-depth: 0` in the checkout action to get full git history (but this increases CI time).
### Files to Modify
1. `build.gradle.kts`: Add the custom line length check step and `ratchetFrom('origin/main')`
2. `.github/workflows/build.yml` (and other relevant workflows): Add `git fetch origin main --depth=1` step
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] [Improvement] Add line length check (100 chars) to Spotless configuration [gravitino]
Posted by "sdavids (via GitHub)" <gi...@apache.org>.
sdavids commented on issue #9834:
URL: https://github.com/apache/gravitino/issues/9834#issuecomment-4073143383
If this is to be added, the line length should be configurable.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org