Skip to content

Files

Latest commit

 

History

History
35 lines (22 loc) · 675 Bytes

OptionalUnit.md

File metadata and controls

35 lines (22 loc) · 675 Bytes

Pattern: Unnecessary use of Unit

Issue: -

Description

It is not necessary to define a return type of Unit on functions or to specify a lone Unit statement. This rule detects and reports instances where the Unit return type is specified on functions and the occurrences of a lone Unit statement.

Example of incorrect code:

fun foo(): Unit {
    return Unit 
}
fun foo() = Unit

fun doesNothing() {
    Unit
}

Example of correct code:

fun foo() { }

// overridden no-op functions are allowed
override fun foo() = Unit

Further Reading