Suppressed rules should not execute autoCorrect #4295
Replies: 5 comments 1 reply
-
The detekt code related with auto correction is really minimum. It's basically this: fun withAutoCorrect(block: () -> Unit) {
if (autoCorrect) {
block()
}
} That function can know if the issue that it is fixing is suppressed or not. Even more, that function doesn't know if an issue exist or not. It just execure some code if autoCorrect is enabled. We could create a "more complex" extension function that foce you to provide a Do you have the time to do it? do you want to give it a try? |
Beta Was this translation helpful? Give feedback.
-
No, sorry, I don't have time for this now. Does this mean that it's up to the author of the autoCorrect code to decide (as they have all the info available either by domain knowledge or by functions available):
As a "quick fix" we could add the existence of this isSuppressedBy to the docs? |
Beta Was this translation helpful? Give feedback.
-
Yes, right now is the rule author who should decide this.
Sure, please go ahead! The documentation about auto correctable rules is really minimum right now. Note: I don't recommend you to ignore the |
Beta Was this translation helpful? Give feedback.
-
Thinking a bit more about this. Do we want to implement this? I think that it shouldn't be implemented on the core of detekt. It should be the rule author taking this decission. So, the only action we could do on this issue is to decide if we want to support it as authors of formatting. |
Beta Was this translation helpful? Give feedback.
-
This is probably worth consideration when we evolve |
Beta Was this translation helpful? Give feedback.
-
Environment
Detekt: 1.14.0 and 1.15.0 (can't upgrade further)
Gradle: 6.7 and 6.9.1
OS: Windows 10
Expected Behavior
Suppressed rules should not execute autoCorrect.
Current Behavior
Suppressed rules execute autoCorrect.
Context
I wrote a custom rule ("CompanyLogging") that changes logging calls that are for the wrong class. For example:
where
D
is wrong, it should be a logger forC
, so the autoCorrect changes it toNow, what happens if I want to keep it
D
, because it makes sense? For exampleThe problem is that, while suppressed, the code is changed to
so every time someone would run autoCorrect they would have to revert this change.
This prevents automated autoCorrect as well, because it would be committed every time a PR branch is autoCorrected.
Beta Was this translation helpful? Give feedback.
All reactions