Skip to content

CanBeNonNullable: Check parent condition for checking if nullability info is used or not - #6064

Merged
BraisGabin merged 1 commit into
detekt:mainfrom
atulgpt:fixes/5799
May 5, 2023
Merged

CanBeNonNullable: Check parent condition for checking if nullability info is used or not#6064
BraisGabin merged 1 commit into
detekt:mainfrom
atulgpt:fixes/5799

Conversation

@atulgpt

@atulgpt atulgpt commented May 1, 2023

Copy link
Copy Markdown
Contributor

Fixes: #5799

@codecov

codecov Bot commented May 1, 2023

Copy link
Copy Markdown

Codecov Report

Merging #6064 (226f9f5) into main (158aa2a) will decrease coverage by 0.02%.
The diff coverage is 71.42%.

@@             Coverage Diff              @@
##               main    #6064      +/-   ##
============================================
- Coverage     84.86%   84.84%   -0.02%     
  Complexity     3975     3975              
============================================
  Files           564      564              
  Lines         13300    13300              
  Branches       2325     2327       +2     
============================================
- Hits          11287    11285       -2     
  Misses          870      870              
- Partials       1143     1145       +2     
Impacted Files Coverage Δ
.../arturbosch/detekt/rules/style/CanBeNonNullable.kt 79.33% <71.42%> (-0.74%) ⬇️

@cortinico cortinico changed the title Check parent condition for checking if nullability info is used or not CanBeNonNullable: Check parent condition for checking if nullability info is used or not May 1, 2023
val code = """
fun foo(a: Int?, other: Int) {
when {
a != null || other % 2 == 0 -> println(2 + other)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I always have doubts about this. Basically it is a boolean and makes the function do something if it is true. But probably that's probably work for another rule.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hi, @BraisGabin can you create an issue about the smell here?

@BraisGabin BraisGabin added this to the 1.23.0 milestone May 5, 2023
@BraisGabin
BraisGabin merged commit 731c6de into detekt:main May 5, 2023
@atulgpt
atulgpt deleted the fixes/5799 branch May 5, 2023 07:38
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 on CanBeNonNullable: not differentiating between && and || in some scenarios

4 participants