Skip to content

Make ktlint Conditional On New Vs Existing Kotlin Files#3803

Open
Jignesh-dimagi wants to merge 1 commit into
masterfrom
ktlint-bloated-pr-issue
Open

Make ktlint Conditional On New Vs Existing Kotlin Files#3803
Jignesh-dimagi wants to merge 1 commit into
masterfrom
ktlint-bloated-pr-issue

Conversation

@Jignesh-dimagi

@Jignesh-dimagi Jignesh-dimagi commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

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.

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>
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Updated the AGENTS.md “AI Workflow: ktlint” section with detailed instructions for running ktlintFile on new and existing Kotlin files, avoiding unrelated formatting changes, and manually resolving violations that cannot be auto-fixed.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description only includes Technical Summary and omits the required Product Description, Safety Assurance, and Labels and Review sections. Add the missing template sections, including user-facing impact, safety story, test coverage, and the labels/review checklist items.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: conditional ktlint handling for new versus existing Kotlin files.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch ktlint-bloated-pr-issue

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Jignesh-dimagi Jignesh-dimagi marked this pull request as ready for review July 10, 2026 06:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fdae6b8d-8b90-4aea-8361-13593fabf1d6

📥 Commits

Reviewing files that changed from the base of the PR and between 900088c and 2ff92dd.

📒 Files selected for processing (1)
  • AGENTS.md

Comment thread AGENTS.md
Comment on lines 56 to +65
## 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 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

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 27.03%. Comparing base (24dd23f) to head (2ff92dd).
⚠️ Report is 54 commits behind head on master.

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.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-integration-tests Skip android tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants