sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`unicorn/prefer-spread` treats `string.slice(0)` like an array

yukulele opened this issue · comments

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

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?

The issue is that most (all?) unicorn rules don't/can't use types to avoid false positives.