saveourtool/diktat

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

Open

#1,491 创建于 2022年8月9日

在 GitHub 查看
 (0 评论) (0 反应) (1 负责人)Kotlin (40 fork)github user discovery
buggood first issue

仓库指标

Star
 (571 star)
PR 合并指标
 (PR 指标待抓取)

描述

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

贡献者指南