Skip to content

feat(lint): add UncheckedFlagAccess detector (#157)#177

Closed
kirich1409 wants to merge 1 commit intomainfrom
feat/lint-unchecked-flag-access
Closed

feat(lint): add UncheckedFlagAccess detector (#157)#177
kirich1409 wants to merge 1 commit intomainfrom
feat/lint-unchecked-flag-access

Conversation

@kirich1409
Copy link
Copy Markdown
Contributor

Summary

  • Adds UncheckedFlagAccessDetector — an Android Lint rule (WARNING, priority 8) that flags calls to @BehindFlag("flagName")-annotated functions when the call site is not inside a valid guard context
  • Valid guard contexts (v1): if/when expression referencing the flag by name, or an enclosing function annotated with the same @BehindFlag
  • Registers the new issue in FeaturedIssueRegistry

Implementation notes

  • @BehindFlag has SOURCE retention, so annotations are read via PSI (PsiAnnotation) rather than descriptors; ConstantEvaluator.evaluate() is used to resolve string values from Kotlin sources
  • USwitchClauseExpression.caseValues is checked in addition to USwitchExpression.expression to handle both when (flag) { ... } (subject form) and when { flag -> ... } (conditionless form), including lint's TestMode.IF_TO_WHEN rewrite

Test plan

  • 2 positive cases (bare unguarded call; if-block with unrelated condition) → expectWarningCount(1)
  • 5 negative cases: if (flag) guard, @BehindFlag enclosing function, no annotation, when (flag) subject — all expectClean()
  • All 14 tests in :featured-lint-rules:test pass

Closes #157

🤖 Generated with Claude Code

Detects calls to @BehindFlag-annotated functions that are not guarded
by a valid flag context (if/when referencing the flag by name, or
enclosing function annotated with the same @BehindFlag).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@qodo-code-review
Copy link
Copy Markdown

ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@kirich1409
Copy link
Copy Markdown
Contributor Author

Closing: content merged in #176.

@kirich1409 kirich1409 closed this Apr 29, 2026
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.

feat(lint): add UncheckedFlagAccess detector for Android Lint

1 participant