scalastyle / scalastyle-sbt-plugin

scalastyle-sbt-plugin
Apache License 2.0
139 stars 52 forks source link

Array of magic numbers #54

Closed meghana-viswanath closed 7 years ago

meghana-viswanath commented 8 years ago

Hi,

The magic number rule, in my opinion, incorrectly flags a collection of numbers assigned to a variable, eg. val numbers = Array(5,10,20,25,30) The intention behind the array is explicitly defined by the variable name.

Thanks, Meghana.

danwerner commented 7 years ago

We have a similar case in our codebase:

val dimensions = Seq(
  Dimensions(120, 240),
  Dimensions(240, 360),
  ...
)

It would be very difficult to spot all such cases automatically, I imagine, especially with nested collections and custom collections. The workaround that works well for us is to surround the val definition with // scalastyle:on/off magic.number. FWIW.

matthewfarwell commented 7 years ago

I too think that it would be difficult to spot all of these problems automatically. I would suggest using scalastyle:on/off. Closed. If there is still an issue, please reopen.