Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnusedPrivateProperty does not detect unused property named "logger" #7222

Open
Chris-Goetz opened this issue Apr 24, 2024 · 2 comments
Open

Comments

@Chris-Goetz
Copy link

Expected Behavior

detekt should find unused properties for which no exception is defined.

Observed Behavior

detekt does not find unused properties named "logger".

Steps to Reproduce

Screenshot from 2024-04-24 13-29-18

Context

The documentation statesthe default allowed values are: allowedNames (default: '_|ignored|expected|serialVersionUID') - "logger" is not listed here.
We also have no exceptions in our config for that rule defined:

---
build:
  weights:
    LongParameterList: 0
    TooManyFunctions: 0

complexity:
  excludes: ["**/test/**"]

formatting:
  MaximumLineLength:
    excludes: ["**/test/**"]
  NoWildcardImports:
    active: false
  TrailingCommaOnCallSite:
    active: true
  TrailingCommaOnDeclarationSite:
    active: true

naming:
  FunctionParameterNaming:
    excludes: ["**/test/**"]
  ClassNaming:
    excludes: ["**/test/**"]
  MemberNameEqualsClassName:
    active: false

style:
  MaxLineLength:
    excludes: ["**/test/**"]
  WildcardImport:
    active: false
  SerialVersionUIDInSerializableClass:
    active: false

config:
  validation: true

Your Environment

  • Version of detekt used: 1.23.5
  • Version of Gradle used (if applicable):

Gradle 8.6

Build time: 2024-02-02 16:47:16 UTC
Revision: d55c486870a0dc6f6278f53d21381396d0741c6e

Kotlin: 1.9.20
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.10 (Private Build 17.0.10+7-Ubuntu-122.04.1)
OS: Linux 6.5.0-28-generic amd64

@atulgpt
Copy link
Contributor

atulgpt commented Apr 24, 2024

Below TC is passing though

@Test
fun `does report private logger property in top level`() {
    val code = """
       private val logger = 2
    """.trimIndent()

    assertThat(subject.lintWithContext(env, code))
        .hasSize(1)
}

is your type resolution set properly?

@Chris-Goetz
Copy link
Author

Hi,
sorry for the late answer, one of my Outlook filters has eaten up the notification.

I've tried to run 'detektMain' wich gave me a lot of new findings but the unused logger property was still ignored.
Then I tried to assign the value '2' to logger, like in your test. That was found by both, the 'detekt' and the 'detektMain' task.
After that, I tried to assing 'private val logger = Logger.getLogger("foo")' and that was also found.

It must have something to do with the 'KotlinLogging.logger {}'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants