You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would like to be able to detect unnecessary safe call like:
val notNullValue = "some-label"
val length1 = notNullValue?.length
val length2 = requireNotNull(notNullValue).length
val length3 = checkNotNull(notNullValue).length
Context
This rule will be helpful with refactoring code and improves code performance.
For example:
// Before changes
val someValue: String? = null
val length = someValue?.length
// After refactoring
val someValue: String = DEFAULT_VALUE
val length = someValue?.length // ? the safe call still here,
// but should be better to remove this operator
The text was updated successfully, but these errors were encountered:
This rule will be helpful with refactoring code and improves code performance.
Not necessarily does it improve performance, since the optimizer in the compiler suite checks this cases and doesn't generate the corresponding bytecode for the if (foo != null) foo.bar() statement.
I think both rules are valuable for detekt. Thanks @cortinico ! That's awesome. Do you also submit a PR for the UnnecessaryNotNullOperators rule? That would be great.
Expected Behavior of the rule
I would like to be able to detect unnecessary safe call like:
Context
This rule will be helpful with refactoring code and improves code performance.
For example:
The text was updated successfully, but these errors were encountered: