Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@VitalyVPinchuk
Copy link
Contributor

For #4492
Report code smell when null-check expression returns 'Unit'

The rule will report code smell when null-check expression returns 'Unit'
# Conflicts:
#	detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/CanBeNonNullable.kt
@marschwar
Copy link
Contributor

How about this example? If there is any side effect before the guard statement it should not report an issue, right?

fun foo(a: Int?) {
    println("side effect")
    if (a == null) return
    println(a)
}

@VitalyVPinchuk
Copy link
Contributor Author

Hmm... I didn't think of it.
We'll lose part of the side effect if we make parameter non-nullable. Probably, it's better not to report such a case...
Give your thoughts, please

@marschwar
Copy link
Contributor

That was exactly my thought. I would not report if there is any side effect before the guard statement. Since detecting if it really is a side effect would be hard, I would not allow anything before the guard.

@VitalyVPinchuk
Copy link
Contributor Author

You're right. I'll fix it.

@BraisGabin BraisGabin merged commit 4742842 into detekt:main Jun 24, 2022
@cortinico cortinico added this to the 1.21.0 milestone Jun 24, 2022
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.

4 participants