diktat icon indicating copy to clipboard operation
diktat copied to clipboard

[`INVERSE_FUNCTION_PREFERRED`] should not replace `!ClosedRange.isEmpty()`

Open illarionov opened this issue 1 year ago • 2 comments

Describe the bug

Given the following code:

val range: ClosedRange<Int> = 0..1
check(!range.isEmpty())

Diktat suggests replacing this with the nonexistent ClosedRange.isNotEmpty() function:

[INVERSE_FUNCTION_PREFERRED] it is better to use inverse function: isNotEmpty() instead of !isEmpty() (diktat-ruleset:inverse-method)

Expected behavior

Rule should not be triggered when the isNotEmpty function does not exist.

Environment information

  • diktat version: 1.2.5
  • how is diktat run (CLI, plugin, etc.): CLI

illarionov avatar Jun 22 '23 07:06 illarionov

Haha, nice catch, thank you! We will fix it. But actually strange that they did not implement isNotEmpty() function, may be need to contribute to the stdlib 🤔

orchestr7 avatar Jun 22 '23 09:06 orchestr7

As a quick workaround you can use @Suppress("INVERSE_FUNCTION_PREFERRED")

orchestr7 avatar Jun 22 '23 09:06 orchestr7