eslint-plugin-unicorn
eslint-plugin-unicorn copied to clipboard
Rule proposal: `prefer-operator-assignment`
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=
ESLint's operator-assignment doesn't catch case with template literal interpolation
Can you open an issue on ESLint about the operator-assignment
covering this case too?
I opened, but it was rejected https://github.com/eslint/eslint/issues/15840#event-6557480224
Accepted