saveourtool/diktat

`WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR` false positive

Open

#1,935 创建于 2024年7月1日

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

仓库指标

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

描述

Describe the bug

Here's a piece of code I have:

public abstract class Observable<T> {
    public abstract val value: T

    public abstract fun subscribe(subscriber: Subscriber<T>): Subscription

    public inline fun <R> transform(crossinline block: Transform<T, R>): Observable<R> =
        object : Observable<R>() {
            override fun subscribe(subscriber: Subscriber<R>): Subscription =
                this@Observable.subscribe { subscriber(block(it)) }

            @Suppress("WRONG_NAME_OF_VARIABLE_INSIDE_ACCESSOR")
            override val value: R
                get() = block(this@Observable.value) // I can't use the `field` property here
        }

    public companion object
}

The problem is diktat claims I have to use a field property instead of this@Observable.value which isn't technically possible in this case. Perhaps the case is non-trivial for the parser, and if I had used a named private class instead of an anonymous object, this could have been avoided, but I think I should point out that such snippets happen too.

Environment information

  • diktat version: 2.0.0
  • build tool (maven/gradle): Gradle
  • how is diktat run (CLI, plugin, etc.): plugin
  • kotlin version: 2.0.0
  • operating system: macOS Sonoma 14.3

贡献者指南