KT.UNTIL_INSTEAD_OF_RANGE_TO

Call to '..' operator can be replaced with 'until'

Reports calls to '..' operator instead of calls to 'until'. 'until' is applicable in cases where the upper range value is described as some value subtracted by 1. 'until' helps to prevent off-by-one errors.

Noncompliant Code

Copy
for (i in 0 .. 10 - 1) {}
val range = 0 .. 10 - 1

Compliant Code

Copy
for (i in 0 until 10) {}
val range = 0 until 10

The content on this page is adapted from the Detekt Docs. Copyright ©2022 The Detekt Team. All rights reserved. https://detekt.dev/comments.html