Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Comments/KDoc indentation not checked #297

Closed
jfresen opened this issue Oct 18, 2018 · 6 comments · Fixed by #1397
Closed

Comments/KDoc indentation not checked #297

jfresen opened this issue Oct 18, 2018 · 6 comments · Fixed by #1397
Labels
Milestone

Comments

@jfresen
Copy link

jfresen commented Oct 18, 2018

In the following code, only the last two errors in indentation are detected:

fun foo() {               
    /**
       * not detected
     */
    /*
       * not detected
     */
    //
      // detected
    //
    var foo = 1
      foo += 1 // detected
    foo -= 1
}
@shyiko shyiko changed the title Incorrect indentation not detected in Javadoc and block comments Comments/KDoc indentation not checked Feb 12, 2019
@shyiko
Copy link
Collaborator

shyiko commented Mar 11, 2019

ktlint -F --experimental (since ktlint@0.31.0) produces

fun foo() {
    /**
     * not detected
     */
    
    /*
       * not detected
     */
    //
    // detected
    //
    var foo = 1
    foo += 1 // detected
    foo -= 1
}

/**/ content is not checked because it's essentially freeform. I suppose we can check whether all !blank lines start with * and align them if they are but it's not implemented yet.

@yukukotani
Copy link
Contributor

yukukotani commented Oct 2, 2019

@shyiko You mean the code below should be allowed?

fun foo() {
    /*
            * comment
     */
}

In my opinion, the text in comment should be freeform, but starting * should be aligned.

fun foo() {
    /*
     * ugly
     *         indent
     *    in comment
     * should be allowed
     */
    /*
     * ugly
           * indent
       * of comment head
     * should not be allowed
     */
}

@Tapchicoma
Copy link
Collaborator

I would agree that * should be aligned and have whitespace after, then text could be free-form.

@paul-dingemans paul-dingemans added this to the 0.45.0 milestone Feb 16, 2022
@paul-dingemans
Copy link
Collaborator

The issue still (partly) exists in current 0.44.0 version. The KDoc and EOL comments are fixed. The incorrectly indented block comment is still undetected. Original example is now formatted as:

fun foo() {
    /**
     * not detected
     */
    val bar = 1
    /*
       * not detected
     */
    //
    // detected
    //
    var foo = 1
    foo += 1 // detected
    foo -= 1
}

@matthewadams
Copy link

matthewadams commented Mar 10, 2023

It'd be nice if this also hard-wrapped KDoc (Javadoc) lines at some standard margin.

So that, with an 80-character margin for example,

/**
 * This is a really really really really really really really really really really really really really really really really really long line.
 */

is reformatted to

/**
 * This is a really really really really really really really really really
 * really really really really really really really really long line.
 */

@paul-dingemans
Copy link
Collaborator

It'd be nice if this also hard-wrapped KDoc (Javadoc) lines at some standard margin.

So that, with an 80-character margin for example,

/**
 * This is a really really really really really really really really really really really really really really really really really long line.
 */

is reformatted to

/**
 * This is a really really really really really really really really really
 * really really really really really really really really long line.
 */

This is not related to the original issue. Also, I don't think that KDOC should be wrapped. If you really would like to have such functionality it is best to write a custom rule for it. See https://pinterest.github.io/ktlint/api/custom-rule-set/ for a starting point to create a custom rule.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants