You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following test added in MagicNumberSpec fails:
given("ignoring named arguments is off") {
fun code(numberString: String) = compileContentForTest("""
data class Model(
val someVal: Int,
val other: String = "default"
)
var model = Model($numberString)
""")
it("should not ignore int") {
val rule = MagicNumber(TestConfig(mapOf("ignoreNamedArgument" to "true")))
assertThat(rule.lint(code("53"))).hasSize(1)
}
}
It looks like this behaviour is not correct, since Model($numberString) will resolve to a non-named argument being passed a magic number. ignoreNamedArguments option set to true should not affect lint result in this case, but it does. In our codebase ignoreNamedArgument: true makes magic numbers like this:
internal fun String.appendRandomDigit() = plus(Random().nextInt(10))
go undetected
The text was updated successfully, but these errors were encountered:
How old is your branch? Your not on the master branch, are you?
There is no such test case in master.
given("ignoring named arguments") {
given("in constructor invocation") {
funcode(numberString:String) = compileContentForTest(""" data class Model( val someVal: Int, val other: String = "default" ) var model = Model(someVal = $numberString)""")
it("should not ignore int by default") {
assertThat(MagicNumber().lint(code("53"))).hasSize(1)
}
....
Right, there's no such test - I've added it to show that the rule is behaving incorrectly.
The test you've pasted checks that if ignoreNamedArgument = false then named number is not ignored.
The test I've added checks whether if ignoreNamedArgument = true then unnamed number is catched, but it fails. But ignoreNamedArgument should have no effect on unnamed arguments, right? Essentially once someone sets ignoreNamedArguments = true in detekt config, then all number parameters are ignored by the magic number rule, named or not
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related topics.
lockbot
locked as resolved and limited conversation to collaborators
Jun 20, 2019
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The following test added in
MagicNumberSpec
fails:It looks like this behaviour is not correct, since
Model($numberString)
will resolve to a non-named argument being passed a magic number.ignoreNamedArguments
option set totrue
should not affect lint result in this case, but it does. In our codebaseignoreNamedArgument: true
makes magic numbers like this:go undetected
The text was updated successfully, but these errors were encountered: