Metadata

ID: kotlin-code-style/function-type-modifier-spacing

Language: Kotlin

Severity: Notice

Category: Code Style

Description

There should be a single space for type modifiers for a function type and the parameters or receiver.

Non-Compliant Code Examples

// Function type
val process: suspend() -> Unit = {}

// Function type with receiver
val process: suspend   String.() -> Unit = { println(this) }

// Function type with nullable receiver
val process: suspend   String?.() -> Unit = { if (this != null) println(this) }

// Nullable function type
val process: (suspend() -> Unit)? = null

// Function type as parameter
suspend fun execute(task: suspend  () -> Unit) { task() }

Compliant Code Examples

// Function type
val process: suspend () -> Unit = {}

// Function type with receiver
val process: suspend String.() -> Unit = { println(this) }

// Function type with nullable receiver
val process: suspend String?.() -> Unit = { if (this != null) println(this) }

// Nullable function type
val process: (suspend () -> Unit)? = null

// Function type as parameter
suspend fun execute(task: suspend () -> Unit) { task() }
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Security