eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

`unicorn/no-for-loop` false positive: loop through a string (returned by `string.slice()`)

Open panmenghan opened this issue 2 years ago • 0 comments

const str = '123'.slice(1) // <-- maybe string.slice() triggers the bug

for (let i = 0; i < str.length; i++) { // <-- unicorn/no-for-loop
  console.log(str[i], i)
}

after auto-fix:

const str = '123'.slice(1)

for (const [i, element] of str.entries()) { // <-- Property 'entries' does not exist on type 'string'
  console.log(element, i)
}

panmenghan avatar Apr 29 '22 06:04 panmenghan