Skip to content

KDoc comment format #2982

@marchuk0

Description

@marchuk0

Expected Rule behavior

The rule should check whether Kdoc comment conforms to one of the following rules:

  1. This Kdoc is a single-line comment that starts with /** and ends with */.
  2. This Kdoc is a multi-line comment and
    • Kdoc comment starts with the line /**
    • Kdoc comment ends with the line */
    • all other lines start with * except the empty lines that should look like * (with no trailing whitespace)
    • The number of leading whitespaces is the same for each line, except the first line of the Kdoc comment where the number of whitespaces is one whitespace less than other lines.

The Kotlin coding conventions or Android Style Guide do not strictly define the KDoc comment format, but examples have the same well-readable format.

  1. https://kotlinlang.org/docs/kotlin-doc.html#kdoc-syntax
  2. https://developer.android.com/kotlin/style-guide#formatting_2

Examples of good KDoc comments:

/**
 * A group of *members*.
 *
 * This class has no useful logic; it's just a documentation example.
 *
 * @param T the type of a member in this group.
 * @property name the name of this group.
 * @constructor Creates an empty group.
 */

/** A group of *members* */

Examples of bad Kdoc comments:

/***
 * A group of *members*.
 *
 * This class has no useful logic; it's just a documentation example.
 *
 * @param T the type of a member in this group.
 * @property name the name of this group.
 * @constructor Creates an empty group.
 */

/** A group of *members*.
 *
 * This class has no useful logic; it's just a documentation example.
 *
 * @param T the type of a member in this group.
 * @property name the name of this group.
 * @constructor Creates an empty group.
 */


/**A group of *members* */

Additional information

  • Current version of ktlint: 1.5.0
  • Styleguide section:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions