Skip to content

fix(kotlin): parse ktlint reports and scope formatting to eligible files - #778

Open
daBOB wants to merge 1 commit into
peteromallet:mainfrom
daBOB:fix/kotlin-ktlint-integration
Open

daBOB wants to merge 1 commit into
peteromallet:mainfrom
daBOB:fix/kotlin-ktlint-integration

Conversation

@daBOB

@daBOB daBOB commented Sep 23, 2026

Copy link
Copy Markdown

Kotlin's ktlint registration uses a flat JSON parser, but ktlint reports nested errors arrays per file. Its default warning preamble can also invalidate JSON. This drops real findings. The generic directory formatter additionally lacks the CLI's normal no-path calling behavior and cannot constrain formatting to selected, eligible source files.

Add a dedicated ktlint parser and suppress log preambles with --log-level=none. Preserve rule and column details and give separate violations on the same line distinct identities. Malformed reporter output raises a parser error instead of appearing clean.

Use a Kotlin-specific fixer that formats selected eligible files through stdin and validates the result before atomically writing it. This respects configured exclusions and never treats filenames as globs. Dry runs do not write. Invalid syntax, failed tools, malformed validation output, and concurrent source edits preserve the original file. Permissions are retained. Remaining uncorrectable violations stay unresolved for the next scan. Other language fixers are unchanged.

Validation:

  • 120 focused generic-plugin, Kotlin and autofix tests passed with ktlint 1.8.0, including 18 new regression cases.
  • Initial regressions: 9 failed and 2 passed before production edits.
  • Real ktlint tests exercise nested output, exclusion handling, formatting through the CLI's no-path fixer contract, literal bracketed filenames, dry runs, malformed Kotlin and uncorrectable violations.
  • Read-only validation across a real Android project reported 2,572 violations in 190 eligible files and zero excluded findings. Hashes of 228 Kotlin files and seven scanner JSON files were unchanged.
  • Ruff on all four changed files and git diff --check passed.

Full python -m pytest desloppify/tests/ -q: 5,826 passed, 5 skipped, 2 failed. Both failures are duplicated review-prompt tests asserting Previously flagged issues; both also fail against the unchanged upstream base.

This branch has not been deployed

No deployments
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.

1 participant