diktat icon indicating copy to clipboard operation
diktat copied to clipboard

False positive `KDOC_WITHOUT_RETURN_TAG` for functions returning `Unit` (implicit) or `Nothing` (explicit)

Open 0x6675636b796f75676974687562 opened this issue 3 years ago • 2 comments

DiKTat should require no @return tags in KDoc comments for expression-body functions with an implicit Unit or an explicit Nothing return types. In the below cases, a KDoc without any @return tag is sufficient:

/**
 * This function does nothing.
 */
fun f1() = Unit

/**
 * This function does nothing.
 */
fun f2() = kotlin.Unit

/**
 * This function fails immediately.
 */
fun fail1(): Nothing = TODO()

/**
 * This function fails immediately.
 */
fun fail2(): kotlin.Nothing = TODO()

Environment information

  • diktat version: 1.2.0
  • build tool (maven/gradle): Maven
  • how is diktat run (CLI, plugin, etc.): Maven plug-in
  • kotlin version: 1.7.0
  • operating system: Windows

Zero priority, not critical at all (keeping in mind the number of issues we have).

orchestr7 avatar Jun 27 '22 11:06 orchestr7

I think we decided to check only explicit Unit because without type resolution it is too complex to check actual return type. Explicit Nothing, OTOH, can be easily added along with explicit Unit

petertrr avatar Jun 27 '22 11:06 petertrr