sindresorhus/eslint-plugin-unicorn
Rule proposal: `prefer-operator-assignment`
Closed
#1,805 opened on May 2, 2022
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 30d)
Description
Description
if the new string starts with the previous string, prefer operator assignment as less code is written
Fail
foo = foo + 'baz qux'
foo = `${foo} baz ${qux}`
Pass
foo += 'baz qux'
foo += ` baz ${qux}`
Additional Info
ESLint's operator-assignment doesn't catch case with template literal interpolation https://eslint.org/demo#eyJ0ZXh0IjoibGV0IGZvbyA9IGAke2Zvb30gYmF6ICR7cXV4fWBcbmZvbyA9IGZvbyArICdiYXogcXV4JyIsIm9wdGlvbnMiOnsicGFyc2VyT3B0aW9ucyI6eyJlY21hVmVyc2lvbiI6ImxhdGVzdCIsInNvdXJjZVR5cGUiOiJzY3JpcHQiLCJlY21hRmVhdHVyZXMiOnt9fSwicnVsZXMiOnsiY2FwaXRhbGl6ZWQtY29tbWVudHMiOjIsIm9wZXJhdG9yLWFzc2lnbm1lbnQiOjJ9LCJlbnYiOnt9fX0=