saveourtool/diktat

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

Open

#1491 aperta il 9 ago 2022

Vedi su GitHub
 (0 commenti) (0 reazioni) (1 assegnatario)Kotlin (40 fork)github user discovery
buggood first issue

Metriche repository

Star
 (571 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor