Parens Before Trailing Lambda

ID

kotlin.parens_before_trailing_lambda

Severity

info

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Kotlin

Tags

readability, style

Description

Reports empty argument lists () that immediately precede a trailing lambda when the function accepts no positional arguments other than the lambda itself. The empty parentheses are redundant and should be omitted.

Rationale

The Kotlin style guide prefers foo { …​ } over foo() { …​ } when there are no positional arguments. The cleaner form reduces syntactic noise and is the idiomatic Kotlin style.

// Bad — redundant ()
run() { // FLAW
    println("hello")
}

// Good
run {
    println("hello")
}

// OK — positional arguments are present
listOf(1, 2, 3).fold(0) { acc, v -> acc + v }

Remediation

Remove the empty parentheses () before the trailing lambda.