Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@t-kameyama
Copy link
Contributor

Fixes #2514

@codecov-io
Copy link

codecov-io commented Mar 30, 2020

Codecov Report

Merging #2556 into master will decrease coverage by 1.75%.
The diff coverage is 0%.

Impacted file tree graph

@@             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
Impacted Files Coverage Δ Complexity Δ
...b/arturbosch/detekt/rules/style/UseCheckOrError.kt 41.66% <0%> (-8.34%) 1 <0> (ø)
...gitlab/arturbosch/detekt/rules/style/UseRequire.kt 33.33% <0%> (-5.13%) 1 <0> (ø)
.../gitlab/arturbosch/detekt/rules/ThrowExtensions.kt 0% <0%> (ø) 0 <0> (ø) ⬇️
.../gitlab/arturbosch/detekt/rules/KtValueArgument.kt 0% <0%> (ø) 0 <0> (?)
...ab/arturbosch/detekt/rules/empty/EmptyInitBlock.kt 33.33% <0%> (-16.67%) 1% <0%> (ø)
...ch/detekt/rules/empty/EmptySecondaryConstructor.kt 33.33% <0%> (-16.67%) 1% <0%> (ø)
...t/rules/exceptions/ThrowingExceptionFromFinally.kt 50% <0%> (-16.67%) 1% <0%> (ø)
...tekt/core/processors/ProjectComplexityProcessor.kt 50% <0%> (-12.5%) 2% <0%> (ø)
...sch/detekt/core/processors/KtFileCountProcessor.kt 71.42% <0%> (-11.91%) 2% <0%> (ø)
...detekt/rules/bugs/ExplicitGarbageCollectionCall.kt 31.25% <0%> (-10.42%) 2% <0%> (ø)
... and 260 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 21ea090...7e3b56d. Read the comment docs.

val type = descriptor?.type
type != null && KotlinBuiltIns.isString(type)
} else {
true
Copy link
Member

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)?

Copy link
Member

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

@t-kameyama t-kameyama requested a review from BraisGabin March 30, 2020 10:47
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.

And again a nice fix.. 👍 🚀

fun test(throwable: Throwable) {
if (throwable !is NumberFormatException) throw IllegalArgumentException(throwable)
}
""".trimIndent()
Copy link
Member

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.

Suggested change
""".trimIndent()
"""

else -> throw IllegalStateException(throwable)
}
}
""".trimIndent()
Copy link
Member

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.

Suggested change
""".trimIndent()
"""


describe("UseCheckOrError rule") {

it("reports if a an IllegalStateException is thrown") {
Copy link
Member

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.

Comment on lines +22 to +23
* if (value == null) throw IllegalStateException("value should not be null")
* if (value < 0) throw IllegalStateException("value is $value but should be at least 0")
Copy link
Member

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()
Copy link
Member

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?

@t-kameyama t-kameyama requested a review from schalkms March 31, 2020 23:58
@schalkms schalkms merged commit 39d8806 into detekt:master Apr 1, 2020
@t-kameyama t-kameyama deleted the issue_2514 branch April 1, 2020 09:52
@arturbosch arturbosch added this to the 1.7.3 milestone Apr 1, 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.

False positive: UseCheckOrError

5 participants