8000 MagicNumber rule: don't check Character, Boolean and null by t-kameyama · Pull Request #3064 · detekt/detekt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

MagicNumber rule: don't check Character, Boolean and null #3064

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

Merged
merged 1 commit into from
Sep 11, 2020

Conversation

t-kameyama
Copy link
Contributor

No description provided.

Copy link
Member
@schalkms schalkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvement!
Does this belong to any issue?
Can we please verify the additional paths with unit tests? Thanks!

@t-kameyama
Copy link
Contributor Author

Does this belong to any issue?

No.

Can we please verify the additional paths with unit tests? Thanks!

context("a boolean value") {
val code = """
fun test() : Boolean {
return true;
}
"""
it("should not be reported") {
val findings = MagicNumber().lint(code)
assertThat(findings).isEmpty()
}
}
context("a non-numeric constant expression") {
val code = "val surprise = true"
it("should not be reported") {
val findings = MagicNumber().lint(code)
assertThat(findings).isEmpty()
}
}

context("a property without number") {
val code = "private var pair: Pair<String, Int>? = null"
it("should not lead to a crash #276") {
val findings = MagicNumber().lint(code)
assertThat(findings).isEmpty()
}
}

Copy link
Member
@schalkms schalkms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this adds a precondition to this rule in order to avoid executing unnecessary rule logic statements. Good! I hope that I got it right.

@schalkms schalkms merged commit 05f2e8e into detekt:master Sep 11, 2020
@t-kameyama t-kameyama deleted the improve_magic_number_rule branch September 11, 2020 22:31
@arturbosch arturbosch added this to the 1.14.0 milestone Sep 13, 2020
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

Successfully merging this pull request may close these issues.

3 participants
0