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

UnnecessaryAbstractClass excludeAnnotatedClasses not working #2360

Closed
jaychang0917 opened this issue Feb 19, 2020 · 4 comments · Fixed by #2361
Closed

UnnecessaryAbstractClass excludeAnnotatedClasses not working #2360

jaychang0917 opened this issue Feb 19, 2020 · 4 comments · Fixed by #2361

Comments

@jaychang0917
Copy link

Expected Behavior

The follow code should pass the rule UnnecessaryAbstractClass.

package com.jaychang.test

import dagger.Binds

@dagger.Module
abstract class Module {
    @Binds
    abstract fun provideFoo(foo: Foo): Foo
}

The config

UnnecessaryAbstractClass:
    active: true
    excludeAnnotatedClasses: "dagger.Module"

Observed Behavior

It fails the rule.

Your Environment

  • Version of detekt used: 1.5.1
  • Version of Gradle used (if applicable): 5.4.1
  • Operating System and version: Mac OS

Thanks!

@cortinico
Copy link
Member

I was able to reproduce this issue. I'm working on a potential fix

@cortinico
Copy link
Member

Fix is here: #2361

Apparently we're not catching fully qualified annotations (like yours @dagger.Module).
Just a couple of side note to your issue:

  1. Specifying excludeAnnotatedClasses: "dagger.Module" is superfluous. That's the default value for that property: https://arturbosch.github.io/detekt/style.html#unnecessaryabstractclass

  2. Your code does not compile as you're missing the import dagger.Module (I assume that was a mistake).

@jaychang0917
Copy link
Author

Thanks.

  1. Your code does not compile as you're missing the import dagger.Module (I assume that was a mistake).

Actually the code compiles.

@cortinico
Copy link
Member

Actually the code compiles.

Yeah you're right, my fault.
Unfortunately this rule relies on imports to work so I had to rework it a bit.

cortinico added a commit to cortinico/detekt that referenced this issue Feb 20, 2020
cortinico added a commit to cortinico/detekt that referenced this issue Feb 20, 2020
cortinico added a commit to cortinico/detekt that referenced this issue Feb 20, 2020
schalkms pushed a commit that referenced this issue Feb 20, 2020
* Extend AnnotationExcluder to catch fully qualified annotations

Fixes #2360

* Remove extra whitespace

* Fix assumption around import of fully qualified annotations

* Move Test snippet to external file

* Including @schalkms suggestion
@arturbosch arturbosch added this to the 1.6.0 milestone Feb 21, 2020
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.

4 participants