Skip to content
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

Magic Number #5

Closed
fatlazycat opened this issue Feb 7, 2012 · 3 comments
Closed

Magic Number #5

fatlazycat opened this issue Feb 7, 2012 · 3 comments
Assignees

Comments

@fatlazycat
Copy link
Contributor

I can see it's only partially implemented but how would currently comply ?

I'd expect

object Something {
val someVal = 50
}

to pass

@matthewfarwell
Copy link
Member

Sorry for the late reply. That's the reason it's only partially implemented. It detects the fact that a magic number is used, but can't tell the context, so there isn't a way to comply.

The eventual rule will be something like you say. If the magic number is part of an expression which is directly assigned to a val, whether in an object, class or trait, then you won't get an error.

It's on my list of things to do, but if you wanted to submit a patch, that would be welcome :-)

@fatlazycat
Copy link
Contributor Author

Yeah will give it a go :)

@ghost ghost assigned matthewfarwell Apr 2, 2012
@matthewfarwell
Copy link
Member

I still haven't implemented this yet, but this is what I'm planning:

A magic number is a number that is not -1,0,1,2 (configurable) which appears. The rule will not raise an warning if the value is directly assigned to a val in an object, such as:

object Foo {
val bar = 5
}

and optionally, the same thing but in a class:

class Foo {
val bar = 5
}

If the number is not a direct assignment, then this will always raise a warning:

object Foo {
val f = new Foo(5) // always raise an error
}

This is because we can't guarantee that Foo is immutable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants