sindresorhus/eslint-plugin-unicorn
Rule proposal: `prefer-operator-assignment`
Chiusa
#1805 aperta il 2 mag 2022
help wantednew rule
Metriche repository
- Star
- (5022 stelle)
- Metriche merge PR
- (Merge medio 4h 30m) (26 PR mergiate in 30 g)
Descrizione
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=