saveourtool/diktat

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

Open

#1,491 opened on Aug 9, 2022

View on GitHub
 (0 comments) (0 reactions) (1 assignee)Kotlin (40 forks)github user discovery
buggood first issue

Repository metrics

Stars
 (571 stars)
PR merge metrics
 (PR metrics pending)

Description

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

Contributor guide