This product is not supported for your selected Datadog site. ().
このページは日本語には対応しておりません。随時翻訳に取り組んでいます。
翻訳に関してご質問やご意見ございましたら、お気軽にご連絡ください

Metadata

ID: kotlin-code-style/angle-bracket-spacing

Language: Kotlin

Severity: Notice

Category: Code Style

Description

This rule enforces consistent spacing around angle brackets used for type parameters in Kotlin. It flags instances where there are unnecessary spaces immediately after the opening < or immediately before the closing >. Inconsistent or excessive spacing within generic type declarations can reduce code readability and deviate from standard Kotlin coding conventions, making the codebase harder to maintain and understand, especially in collaborative environments.

How to remediate

To fix this issue, ensure that there are no extra spaces directly inside the angle brackets. Remove any space between the opening angle bracket (<) and the first type parameter, and between the last type parameter and the closing angle bracket (>). This practice promotes cleaner code that aligns with common Kotlin style guides, enhancing readability and consistency. For example, change Map< Int, String > to Map<Int, String>.

Non-Compliant Code Examples

val foo: Map< Int, String> = mapOf()

val bar: Map<Int, String > = mapOf()

val foo: Map< Int, String > = mapOf()

val baz: Set<String > = setOf()

val bin: Set< String, Pair< Int, String > > = setOf()

Compliant Code Examples

val foo: Map<Int, String> = mapOf()

val bar: Map<Int, String> = mapOf()

val baz: Map<Int, String> = mapOf()
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