Use an EOL comment over a single line block comment

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

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