how to deactivate MagicNumber issues for 'when' branches in detekt.yml #3796
-
i got MagicNumber issues if i have a when (switch case) expression like this: when (x) {
42 -> print("x is 42")
47, 11 -> print("x is 47 or 11")
in 1..10 -> print("x is in the range")
!in 10..20 -> print("x is outside the range")
else -> print("none of the above")
} or here a real world example since i think this is a valid usecase (at least in my current project where i have to decide stuff based on train lines^^) i want to disable the MagicNumber rule for switch cases for the whole project via detekt.yml but could not find how |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
I don't know that I agree with the assessment that this would be a valid use case where those numbers should not be considered magic numbers. Maybe there is a different way to model your domain? But to answer your question; your are right, there is no option to disable magic number detection for when expressions. You can of course disable the rule altogether or add |
Beta Was this translation helpful? Give feedback.
I don't know that I agree with the assessment that this would be a valid use case where those numbers should not be considered magic numbers. Maybe there is a different way to model your domain?
But to answer your question; your are right, there is no option to disable magic number detection for when expressions. You can of course disable the rule altogether or add
@Suppress("MagicNumber")
to the expression.