eslint-plugin-unicorn icon indicating copy to clipboard operation
eslint-plugin-unicorn copied to clipboard

Rule proposal: `prefer-operator-assignment`

Open dimaMachina opened this issue 2 years ago • 3 comments

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=

dimaMachina avatar May 02 '22 15:05 dimaMachina

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?

sindresorhus avatar May 02 '22 16:05 sindresorhus

I opened, but it was rejected https://github.com/eslint/eslint/issues/15840#event-6557480224

dimaMachina avatar May 05 '22 16:05 dimaMachina

Accepted

sindresorhus avatar Jun 05 '22 09:06 sindresorhus