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
privatefunverifyInvalidRange() {
for (i in2 until 1) {} // empty and detekt workfor (i in2 until 2) {} // empty but detekt does not workfor (i in2 until 3) {} // not empty
}
Documentation of Int.until(to: Int): IntRange:
If the [to] value is less than or equal to this value, then the returned range is empty.
2 until 1 - 1 is less than or equal to 2
2 until 2 - 2 is less than or equal to 2
Expected Behavior
The rule will work and the detekt will report an error in case of 2 until 2.
Observed Behavior
Detekt does not report an error in case of 2 until 2.
The problem is only with the until method and only for the case when both parameters are equivalent. For example, the downTo method is correctly determined by detekt. Apparently there is a problem in the code of the io.gitlab.arturbosch.detekt.rules.bugs.InvalidRange class.
The checks for both methods are the same. Although downTo creates an IntRange with the parameter endInclusive, and until with the parameter endInclusive-1.
In all other cases, I did not find any problems with this rule.
This commit handles the case where both given values in the until
function are equal. Closes#2044
Docs for Int.until(to: Int): IntRange:
If the [to] value is less than or equal to this value,
then the returned range is empty.
smyachenkov
pushed a commit
to smyachenkov/detekt
that referenced
this issue
Dec 9, 2019
This commit handles the case where both given values in the until
function are equal. Closesdetekt#2044
Docs for Int.until(to: Int): IntRange:
If the [to] value is less than or equal to this value,
then the returned range is empty.
smyachenkov
pushed a commit
to smyachenkov/detekt
that referenced
this issue
Dec 9, 2019
This commit handles the case where both given values in the until
function are equal. Closesdetekt#2044
Docs for Int.until(to: Int): IntRange:
If the [to] value is less than or equal to this value,
then the returned range is empty.
lockbot
locked as resolved and limited conversation to collaborators
Feb 13, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Documentation of
Int.until(to: Int): IntRange
:2 until 1
- 1 is less than or equal to 22 until 2
- 2 is less than or equal to 2Expected Behavior
The rule will work and the detekt will report an error in case of
2 until 2
.Observed Behavior
Detekt does not report an error in case of
2 until 2
.Steps to Reproduce
I use my task:
File potential_bugs.yml contains:
Context
The problem is only with the
until
method and only for the case when both parameters are equivalent. For example, thedownTo
method is correctly determined by detekt. Apparently there is a problem in the code of theio.gitlab.arturbosch.detekt.rules.bugs.InvalidRange
class.The checks for both methods are the same. Although
downTo
creates anIntRange
with the parameterendInclusive
, anduntil
with the parameterendInclusive-1
.In all other cases, I did not find any problems with this rule.
Environment
java 1.8.0_221
kotlin 1.3.50
detekt 1.1.1
Gradle 5.5.1
macOS Mojave Version 10.14.6 (18G87)
The text was updated successfully, but these errors were encountered: