I'm trying to add a rule to forbid the use of `@Su...
# detekt
h
I'm trying to add a rule to forbid the use of
@Suppress("all")
like this:
Copy code
ForbiddenSuppress:
  active: true
  rules: ["all", "CyclomaticComplexMethod"]
Currently,
@Suppress("all")
isn't being caught, whereas
"CyclomaticComplexMethod"
works as expected. Has anyone encountered this issue? docs: https://detekt.dev/docs/rules/style/#forbiddensuppress
s
I'm guessing that
@Suppress("all")
suppresses the ForbiddenSuppress rule.
This rule is not capable of reporting suppression of itself, as that's a language feature with precedence.
(https://detekt.dev/docs/rules/style/#forbiddensuppress)
h
That is also my suspicion. If so, that's bad since it can be used to abuse/circumvent the rules that we are trying to enforce.
s
This is a tangent, and a personal opinion, but: In my experience, my teams are happier when I explain to them the goal that we're trying to achieve by putting the rules in place, then give them the tools to suppress or change the rules when the rules aren't helping to meet those goals. Enforcing rules makes coders feel untrusted and unempowered, which will just make them see the rule as an unwanted obstacle. Code quality rules work best when the team chooses the rules and sticks to them when they want to, because they want to. So, counterintuitively, less enforcement often means higher compliance. If you really feel the need to enforce a rule absolutely, a pure technical solution like this may not the most effective one.
As for how you would actually do it, you could preprocess the source code before running detekt. A simple
grep
could identify
@Suppress("all")
and simple variations of it.
h
Thats a great point. Given the size of our org, opinions on this naturally vary. My impression is that this suppression often ends up being added hastily just to get a PR through CI quickly, rather than taking the extra few minutes to address the underlying issue, or specifying more detailed suppressions.
s
Ah, I understand! So the goal is to prevent
@Suppress("all")
in order to encourage people to specify more granular suppressions? That actually seems like a good idea, and very much in line with the point I was making 👍 I should not have been so hasty to start preaching 😁
😁 1
h
Haha! Yes, exactly 😄 Maybe I can make it work with a custom Rule that parses annotations.