Make ktlint Conditional On New Vs Existing Kotlin Files#3803
Make ktlint Conditional On New Vs Existing Kotlin Files#3803Jignesh-dimagi wants to merge 1 commit into
Conversation
Avoids reformatting churn on existing files that bloats PRs; new files still get ktlint applied directly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughUpdated the AGENTS.md “AI Workflow: ktlint” section with detailed instructions for running Estimated code review effort: 1 (Trivial) | ~2 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@AGENTS.md`:
- Around line 56-65: Update the “AI Workflow: ktlint” section in AGENTS.md to
document a check-only command or task for existing Kotlin files that does not
apply formatting, and instruct users or .claude/hooks/ktlint-check.sh to use it
for existing files while retaining ktlintFile for new files.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| ## AI Workflow: ktlint | ||
| After editing or creating a Kotlin file, always run the Gradle ktlint task: | ||
| The Gradle ktlint task auto-formats a file and verifies it is clean: | ||
| ```bash | ||
| ./gradlew ktlintFile -PfilePath=<relative-path-to-file> | ||
| ``` | ||
| This task auto-formats the file and then verifies it is clean. If any violations remain that cannot be auto-fixed, resolve them manually. This should be done before committing. | ||
| When to run it depends on whether the Kotlin file is new or existing: | ||
| - **New Kotlin file** — run ktlint directly before committing. | ||
| - **Existing Kotlin file** — you may run ktlint to *check* for violations, but do NOT auto-apply its formatting. On a small change it often reformats unrelated lines, bloating the diff and confusing reviewers. Fix real lint errors in the lines you actually changed, and ask the author before applying formatting to anything else. The author may prefer to let CI flag formatting initially and apply ktlint once at the end of review. | ||
|
|
||
| If any violations remain that cannot be auto-fixed, resolve them manually. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Document a check-only path for existing Kotlin files.
ktlintFile always runs ktlint --format, and .claude/hooks/ktlint-check.sh invokes it for every Kotlin file. Therefore, the instruction not to auto-format existing files cannot be followed with the documented command and may still produce the diff churn this PR aims to prevent.
Document a check-only command/task for existing files (or update the hook/task to distinguish new files from existing ones), while retaining ktlintFile for new files.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@AGENTS.md` around lines 56 - 65, Update the “AI Workflow: ktlint” section in
AGENTS.md to document a check-only command or task for existing Kotlin files
that does not apply formatting, and instruct users or
.claude/hooks/ktlint-check.sh to use it for existing files while retaining
ktlintFile for new files.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3803 +/- ##
============================================
+ Coverage 26.67% 27.03% +0.35%
- Complexity 4609 4711 +102
============================================
Files 974 982 +8
Lines 58102 58427 +325
Branches 6923 6957 +34
============================================
+ Hits 15500 15796 +296
+ Misses 40717 40716 -1
- Partials 1885 1915 +30 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Technical Summary
Updates the ktlint guidance in
AGENTS.md: new Kotlin files get ktlint applied directly, while existing files are only checked (not auto-formatted) to avoid reformatting unrelated lines and bloating PR diffs.