Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for root of receiver in selector expression #7220

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

atulgpt
Copy link
Contributor

@atulgpt atulgpt commented Apr 23, 2024

Fixes #6373

Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 90.47619% with 2 lines in your changes are missing coverage. Please review.

❗ No coverage uploaded for pull request base (main@f1b1bb1). Click here to learn what that means.

Files Patch % Lines
...ch/detekt/rules/bugs/NullCheckOnMutableProperty.kt 71.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7220   +/-   ##
=======================================
  Coverage        ?   84.80%           
  Complexity      ?     3998           
=======================================
  Files           ?      577           
  Lines           ?    12128           
  Branches        ?     2485           
=======================================
  Hits            ?    10285           
  Misses          ?      616           
  Partials        ?     1227           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +147 to +149
val descriptor = (expression.left as? KtNameReferenceExpression)
?.getResolvedCall(bindingContext)
?.resultingDescriptor
Copy link
Member

Choose a reason for hiding this comment

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

Why are you changing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same comment

With this rule, this code is started flagging. As we have written the code as <expression>?.let { it.<someOtherNullableChain> } that could be simplified as <expression>?.<someOtherNullableChain>

Comment on lines +92 to +101
}?.getResolvedCall(bindingContext)
?.resultingDescriptor
?.fqNameOrNull()
?.takeIf(mutableProperties::contains)
?.let { candidateFqName ->
// A candidate mutable property is present, so attach the current
// if-expression to it in the property candidates map.
candidateProperties.getOrPut(candidateFqName) { ArrayDeque() }
.apply { add(expression) }
}
Copy link
Member

Choose a reason for hiding this comment

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

Same as other comment. Looks like this change is unnecessary (let's move it to another PR?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this rule, this code is started flagging. As we have written the code as <expression>?.let { it.<someOtherNullableChain> } that could be simplified as <expression>?.<someOtherNullableChain>

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 negative on UnnecessaryLet in nested nullable property
3 participants