Skip to content

fix: stop flagging used Kotlin imports as unused - #913

Open
zlum wants to merge 1 commit into
peteromallet:mainfrom
zlum:fix/kotlin-unused-imports
Open

zlum wants to merge 1 commit into
peteromallet:mainfrom
zlum:fix/kotlin-unused-imports

Conversation

@zlum

@zlum zlum commented Oct 30, 2026

Copy link
Copy Markdown

Problem

The tree-sitter unused-import check (name must appear in the file) reported Kotlin imports that are used without writing their names:

  • operator conventions, e.g. getValue/setValue imported for var x by mutableStateOf(0). That's 33 false positives on one Compose app. Also contains for in, componentN for destructuring, and others;
  • backtick-escaped names such as Mockito's `when`;
  • import a.B as C aliases (the Kotlin import_alias node was never read);
  • wildcard imports, reported under the package's last segment.

Fix

  • TreeSitterLangSpec.implicit_import_uses: (name, regex) pairs. An import whose name never appears still counts as used when the syntax that calls it is present (e.g. setValue needs a var … by). Kotlin's operator conventions are filled in on KOTLIN_SPEC.
  • Strip backticks from the imported name, read import_alias, skip wildcard imports.

Real unused imports are still reported (it found 6 genuine ones in the same app).

Tested: new tests pass; the full suite on Windows has the same 32 failures as main (path/CRLF issues unrelated to this change). Verified against a real Android app (Kotlin, 113 production files).

🤖 Generated with Claude Code

The name-in-body check reported imports that Kotlin uses without
writing their names:

- operator conventions, e.g. `getValue`/`setValue` imported for
  `var x by mutableStateOf(0)` (33 false positives on one Android app),
  `contains` for `in`, `componentN` for destructuring;
- backtick-escaped names such as Mockito's `when`;
- `import a.B as C` aliases (the `import_alias` node was not read);
- wildcard imports, reported under their package's last segment.

Add `implicit_import_uses` to TreeSitterLangSpec: (name, regex) pairs
that count an import as used when the syntax that calls it is present,
and fill it with Kotlin's operator conventions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to citizenadam/desloppify that referenced this pull request Oct 30, 2026

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