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 false positive #4753
Comments
Isn't this an edge case? I mean, in general a class that only extends another class and does nothing is unnecessary, you could use the base class. In this case the code uses the type but that seems to me like an edge case. I'm not against this change but I'm worried that by allowing this we will add a lot of false negatives. |
If you build an expression hierarchy, or similar, you might introduce an intermediate base class for grouping part of the class hierarchy. |
We face the same issue when wrapping a third party library classes so it's not an edge case. |
I agree, maybe we could add a configuration here but I don't think that it could be even needed. Do you have bandwith to provide a PR? |
Me, not for a month probably. @dawidhyzy-ifolor can you please share your use case in more detail, it might help with unit tests. |
Sure! We have
As Please, let me know if you need more information. |
I think the rule of thumb is because |
* Fix UnnecessaryAbstractClass * Ignore UnnecessaryAbstractClass false positives detekt/detekt#4753 Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Róbert Papp (TWiStErRob) <papp.robert.s@gmail.com>
@BraisGabin May i take this? |
Go ahead |
@BraisGabin |
I'm fine with or without configuration. I suppose that in that case without is better because it keeps the api cleaner but that's your call. I think that no one here have a hard opinion about this topic. |
Ask yourself if there's a possibility for the case you're flagging. Is it possible to write code that passes/fails the rule? And are both of them valid engineering choices? (i.e. due to decisions on preferences or restricted by constraints) |
This issue is closed, but it still happens in 1.21.0 (gradle plugin). Am I doing something wrong? abstract class Foo {
abstract val i: Int
val j = 1
}
abstract class Bar : Foo() // UnnecessaryAbstractClass issue |
I can confirm that the fix did not fix the reported problem: |
@BraisGabin can you please reopen? |
Hi, @EdwarDDay the TC given by you is passing when you run detekt with type resolution on but if you run w/o type resolution then it is failing. Can you confirm in which mode you are running the detekt? |
Yes, I just ran the |
@atulgpt If you meant #4753 (comment), the linked PR TWiStErRob/net.twisterrob.cinema#173 has a commit whose build found this. Navigating the build you can find the workflow file which refers to this hacky w/o type resolution task (Since then, I've moved on to per-module type resolution, but this is an old build.) |
Hi @TWiStErRob yup talking bout #4753 (comment) |
This issue was closed in #5009 released in 1.21.0, and you can see the PR is updating to that version, yet still flagging when I removed the suppression. (screenshot) Since UnnecessaryAbstractClass does not require type resolution: Lines 47 to 49 in 2e6b576
The issue is not solved yet. I re-ran on the latest code I have and it still flags as described in OP w/o type resolution:
with type resolution:
Based on this, the rule just needs an annotation I think, because it's using @BraisGabin do we need to revisit those |
Expected Behavior
Don't report following code:
Observed Behavior
No, it can't:
Fake
interface couldn't extend a class.Base
Note:
String.
might be a red herring, you can ignore that part, just wanted to report what I had. More minimal repro might exist.Steps to Reproduce
Just copy above code into a test or code checked by Detekt 1.20.0.
Context
Real context is creating fakes for a test:
The abstract method is never invoked in the test, so there's no need to implement it, hence using
abstract class
. The class must be unique because it's::class
object is used.Your Environment
--scan
option when running the gradle task): N/AThe text was updated successfully, but these errors were encountered: