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

UnusedImports false positive for enums in annotation attributes (with type resolution) #3131

Closed
vladimirfx opened this issue Oct 6, 2020 · 4 comments · Fixed by #3188
Closed

Comments

@vladimirfx
Copy link

vladimirfx commented Oct 6, 2020

Expected Behavior

When enum constants used in annotation attributes the enum import should not marked as unused.

Steps to Reproduce

In such code BatchFetch import statement marked as unused:

...
import org.eclipse.persistence.annotations.FetchType
...
@Entity
class Sale(
    @Id
    val id: Long,
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    var client: Client,
...
)

Context

We use Gradle plugin with type resolution mode (detektMain task). Bug is introduced after 1.12.0 (witch works as expected).

Your Environment

  • Version of detekt used: 1.14.1
  • Version of Gradle used (if applicable): 6.6.1
  • Operating System and version: MacOS 10.15.7
@chriskn
Copy link

chriskn commented Oct 12, 2020

This issue occurs from version 1.13.0 up. A fix would be highly appreciated

@cortinico
Copy link
Member

In such code BatchFetch import statement marked as unused:

It seems to me that BatchFetch is actually unused in your code.
Can you provide a reproducible example that is not specific to any framework?

@vladimirfx
Copy link
Author

In such code BatchFetch import statement marked as unused:

It seems to me that BatchFetch is actually unused in your code.
Can you provide a reproducible example that is not specific to any framework?

Sorry - my mistake. It is fragment from real project and BatchFetch used and reported too. I've edit sample code. Any enum used in annotation in way EnumName.CONSTANT reported as unused import.

@vladimirfx
Copy link
Author

I've try detekt 1.15.0-RC1 - issue fixed

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

Successfully merging a pull request may close this issue.

5 participants