sindresorhus/eslint-plugin-unicorn
GitHub で見るRule proposal: `no-unnecessary-splice`
Open
#2,359 opened on 2024年5月16日
help wantednew rule
説明
Description
Saw splice being used instead of push/pop/shift/unshift in some projects. AFAIK it brings no performance gain and is harder to read/understand than the latter ones.
Basically bans:
array.splice(index, 0)(can be removed as no-op)array.splice(0, 1)(as substitutable byarray.shift())array.splice(0, 0, element)(as substitutable byarray.unshift(element)- for 1 or more elements)array.splice(array.length - 1, 1)(as substitutable byarray.pop())array.splice(array.length, 0, element)(as substitutable byarray.push(element)- for 1 or more elements)
Should be easy to implement auto-fixer for those replacements.
Fail
array.splice(start, 0)
array.splice(0, 1)
array.splice(array.length, 0, element)
Pass
array.shift()
array.push(element)
Proposed rule name
no-unnecessary-splice
Additional Info
Happy to work on this once accepted (already have a stub).
This would make #2165 not needed any more