In the following code snippet SonarCloud reports the else as redundant:
val useDeviceTimeZone = if (isEmpty()) false else repository.readUseDeviceTimeZoneEnabled()
Here is the full function:
https://sonarcloud.io/organizations/eventfahrplan/rules?open=kotlin%3AS1125&rule_key=kotlin%3AS1125
Hi @tobiaspreuss,
This looks like a true positive to me. Your case seems to be the same as the following line in the noncompliant example of the rule description:
booleanVariable = if (booleanMethod()) false else exp;
It therefore can be replaced as follows:
val useDeviceTimeZone = !isEmpty() && repository.readUseDeviceTimeZoneEnabled()
Cheers,
Sebastian
Thank you. This wasn’t obvious to me.