Skip to content

fix(UnusedVariable): recognize destructured lambda parameters as used#9015

Merged
picklebento merged 3 commits into
mainfrom
claude/fix-unused-variable-8942-WpzwP
Jan 28, 2026
Merged

fix(UnusedVariable): recognize destructured lambda parameters as used#9015
picklebento merged 3 commits into
mainfrom
claude/fix-unused-variable-8942-WpzwP

Conversation

@picklebento
Copy link
Copy Markdown
Member

Summary

  • Fixes false positive in UnusedVariable rule when destructured lambda parameters are used
  • Updates rule to properly track usage of destructured components
  • Adds test cases for destructured lambda parameters

Changes

  • Modified UnusedVariable.kt to recognize destructured lambda parameters as used
  • Added test cases in UnusedVariableSpec.kt to verify the fix

Test plan

  • Added test cases for destructured lambda parameters
  • Verified existing tests still pass
  • Confirmed rule correctly identifies used destructured parameters

Fixes #8942

🤖 Generated with Claude Code

…#8942)

Destructured lambda parameters (e.g., `forEach { (a, b) -> }`) were
incorrectly flagged as unused even when they were used in the lambda body.
Changed to use KaVariableSymbol instead of KaLocalVariableSymbol to properly
resolve references to destructured parameters.

https://claude.ai/code/session_017k8v2kYDUuqB72jZ76Hmvf
The lambda parameters need explicit types for the Kotlin compiler to infer the types correctly.
This fixes the compilation error in the test.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.14%. Comparing base (7508295) to head (5b76e82).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #9015      +/-   ##
============================================
+ Coverage     85.11%   85.14%   +0.02%     
  Complexity     4380     4380              
============================================
  Files           569      569              
  Lines         12249    12255       +6     
  Branches       2643     2642       -1     
============================================
+ Hits          10426    10434       +8     
  Misses          676      676              
+ Partials       1147     1145       -2     

☔ View full report in Codecov by Sentry.
📢 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.

@schalkms schalkms added this to the 2.0.0 milestone Jan 28, 2026
Copy link
Copy Markdown
Member

@BraisGabin BraisGabin left a comment

Choose a reason for hiding this comment

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

LGTM but I think that the comment is not needed.

Comment thread detekt-rules-style/src/main/kotlin/dev/detekt/rules/style/UnusedVariable.kt Outdated
…edVariable.kt

Co-authored-by: Brais Gabín <braisgabin@gmail.com>
@picklebento picklebento enabled auto-merge (squash) January 28, 2026 22:41
@picklebento picklebento merged commit 980c03e into main Jan 28, 2026
21 checks passed
@picklebento picklebento deleted the claude/fix-unused-variable-8942-WpzwP branch January 28, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive UnusedVariable

5 participants