Skip to content

fix(kotlin): retain implicit imports and validate autofix advice - #777

Open
daBOB wants to merge 1 commit into
peteromallet:mainfrom
daBOB:fix/kotlin-implicit-import-usage
Open

daBOB wants to merge 1 commit into
peteromallet:mainfrom
daBOB:fix/kotlin-implicit-import-usage

Conversation

@daBOB

@daBOB daBOB commented Sep 23, 2026

Copy link
Copy Markdown

Kotlin delegates and DSL operators can use imported extensions without spelling their names in the file body. The generic unused-import detector reports these imports anyway; a Kotlin unused cluster then suggests desloppify autofix unused-imports --dry-run even though Kotlin only registers ktlint-violation.

Recognize property delegates, indexing, call expressions and assignment-plugin syntax when checking Kotlin imports. Handle import aliases before matching implicit operator names. This is intentionally conservative without receiver-type resolution: an operator remains potentially used when its corresponding syntax occurs. Ordinary unused imports, comments/strings, read-only delegates and imports without matching syntax retain regression coverage.

Reuse the already validated member commands when suggesting a cluster autofix. Require every member to support the same command; otherwise keep the cluster drill-down command and omit the autofix hint. Manual cluster actions are preserved.

Validation:

  • 177 focused parser, alias, Kotlin syntax and work-queue tests passed (47 new regression cases).
  • Before the fix, the initial regression set produced 24 expected failures and 13 passes.
  • Read-only check of 227 Kotlin/KTS files in a real Android project: upstream reported 47 required imports; patched detector reported 0. They comprised 24 getValue, 20 setValue, and one each of get, invoke, assign. Removing the three Gradle imports caused compiler errors; restoring them restored the build.
  • Full python -m pytest desloppify/tests/ -q: 5,855 passed, 5 skipped, 2 failed. Both failures are the duplicated test_do_run_batches_dry_run_generates_packet_and_prompts assertion for Previously flagged issues; both reproduce with the changed production files restored to upstream HEAD.
  • Ruff on all five changed files and git diff --check passed.

The syntax handling covers delegates, indexing, invocation and the assignment plugin. It does not claim full Kotlin semantic import resolution or add handling for every operator convention. No project code, installed scanner, or scanner state was changed during validation.

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