diktat icon indicating copy to clipboard operation
diktat copied to clipboard

`COMMENT_WHITE_SPACE` false positive when a single-line comment follows an `@Anntotation`

Open 0x6675636b796f75676974687562 opened this issue 2 years ago • 0 comments

Consider I want to suppress certain warnings in the whole file:

@file:Suppress(
    "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE",
    "TOP_LEVEL_ORDER") // False positives

package com.example

import java.lang.String
// import ...

//...

This immediately yields the following error:

example.kt:3:24: [COMMENT_WHITE_SPACE] there should be a white space between code and comment also between code start token and comment text: There should be 0 space(s) before comment text, but are 1 in // False positives (diktat-ruleset:kdoc-comments-codeblocks-formatting)

Okay, removing the extra space:

@file:Suppress(
    "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE",
    "TOP_LEVEL_ORDER")// False positives

Yet, diKTat is still unhappy, and the error message makes no sense:

example.kt:3:23: [COMMENT_WHITE_SPACE] there should be a white space between code and comment also between code start token and comment text: There should be 0 space(s) before comment text, but are 8 in // False positives (diktat-ruleset:kdoc-comments-codeblocks-formatting)

As a workaround, the closing parenthesis can be moved onto the next line, and this no longer results in lint errors:

@file:Suppress(
    "HEADER_MISSING_IN_NON_SINGLE_CLASS_FILE",
    "TOP_LEVEL_ORDER",  // False positives
)

Environment information

  • diktat version: 1.2.3