`unicorn/prefer-spread` treats `string.slice(0)` like an array
yukulele opened this issue · comments
Clément P commented
unicorn/prefer-spread
give wrong fix of string.slice(0)
rule: unicorn/prefer-spread
code:
const original = 'foo'
const copy = original.slice(0)
actual fix:
const original = 'foo'
// Prefer the spread operator over `Array#slice()`
const copy = [...original]
expected fix:
const original = 'foo'
// Primitives are immutables
const copy = original
fisker Cheung commented
give wrong fix of string.splice(0)
There is no String#splice
const copy = original.slice(0)
Don't understand what purpose of slicing a string, shoudn't we use const copy = original
?
Federico Brigante commented
- Merged into #2041
The issue is that most (all?) unicorn rules don't/can't use types to avoid false positives.