报告使用 withIndex() 函数而非索引变量迭代集合的 for 循环。

使用“移除 'for' 循环中的索引”快速修复来清理代码。

示例:


  fun foo(bar: List<String>) {
     for ((index : Int, value: String) in bar.withIndex()) { // <== 'index' is unused
         println(value)
     }
  }

在应用快速修复后:


  fun foo(bar: List<String>) {
      for (value: String in bar) { // <== '.withIndex()' and 'index' are removed
          println(value)
      }
  }