-
-
Notifications
You must be signed in to change notification settings - Fork 821
UseCheckOrError/UseRequire: fix false positive with a non-String argument #2556
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2556 +/- ##
============================================
- Coverage 26.89% 25.13% -1.76%
- Complexity 390 392 +2
============================================
Files 377 378 +1
Lines 6671 7375 +704
Branches 1207 1215 +8
============================================
+ Hits 1794 1854 +60
- Misses 4746 5390 +644
Partials 131 131
Continue to review full report at Codecov.
|
| val type = descriptor?.type | ||
| type != null && KotlinBuiltIns.isString(type) | ||
| } else { | ||
| true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check here if the value argument is a literal string otherwise return false (or null because we don't know)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this. We might want to consider not allowing rules to run for the scenario when no BindingContext is available.
The complexity will increase steadily, if we continue to support both cases.
We might want to start issuing a warning for this case.
CC @3flex @arturbosch
schalkms
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And again a nice fix.. 👍 🚀
| fun test(throwable: Throwable) { | ||
| if (throwable !is NumberFormatException) throw IllegalArgumentException(throwable) | ||
| } | ||
| """.trimIndent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to call .trimIndent() again, since lint() already does it for us.
| """.trimIndent() | |
| """ |
| else -> throw IllegalStateException(throwable) | ||
| } | ||
| } | ||
| """.trimIndent() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to call .trimIndent() again, since lint() already does it for us.
| """.trimIndent() | |
| """ |
|
|
||
| describe("UseCheckOrError rule") { | ||
|
|
||
| it("reports if a an IllegalStateException is thrown") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the user throws an exception with 2 exceptions arguments, whereby the 1st is of type String and the 2nd is of another type. It might be worth to add a test for this case.
| * if (value == null) throw IllegalStateException("value should not be null") | ||
| * if (value < 0) throw IllegalStateException("value is $value but should be at least 0") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch ^^ (Java syntax)
| if (throwable !is NumberFormatException) throw IllegalArgumentException(throwable) | ||
| } | ||
| """.trimIndent() | ||
| assertThat(subject.compileAndLintWithContext(wrapper.env, code)).isEmpty() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a new test to check that if we don't use type solving this same code is not reported?
Fixes #2514