This product is not supported for your selected Datadog site. ().
Cette page n'est pas encore disponible en français, sa traduction est en cours.
Si vous avez des questions ou des retours sur notre projet de traduction actuel, n'hésitez pas à nous contacter.

Metadata

ID: kotlin-code-style/no-single-line-block-comment

Language: Kotlin

Severity: Notice

Category: Code Style

Description

This rule flags single-line block comments (/* ... */) that could be more appropriately replaced by end-of-line (EOL) comments (// ...). A violation occurs when a block comment starts and ends on the same line and is followed only by whitespace until the end of the line. While syntactically valid, using /* ... */ for such cases can be less clear, potentially misleading developers into thinking it’s part of a larger multi-line comment block.

How to remediate

To fix this, replace the single-line block comment with an end-of-line comment. For example, change /* Some comment */ to // Some comment. This improves code readability and aligns with common Kotlin style guidelines where // is used for concise, single-line explanations and /* */ is reserved for multi-line documentation or temporarily disabling code blocks.

Non-Compliant Code Examples

/* Some comment */

val foo = "foo" /* Some comment */

Compliant Code Examples

/*
 * Some comment
 */
val foo = "foo" // Some comment
val foo = { /* no-op */ }

/** Documentation */
val foo = "foo"
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