I have a code base with many strings built via string concatenation. Is there a automated method for replacing all instances of string concatenation with templates? For example:
const a = 'b ' + c;
// becomes:
const a = `b ${c}`;
A script-based solution would be awesome. An editor plugin would be even better. (I am using Visual Studio Code.)
This can be done with eslint. See rule: http://eslint.org/docs/rules/prefer-template.
The following will run a single rule on the src
directory and fix any errors. The rule is a string encoded JSON-like value. The values in the array are 0 - ignore, 1 - warn, 2 - error.
eslint ./src --rule '{prefer-template:[2]}' --fix
Similarly, if you are using TypeScript tslint
can do something similar, although it doesn't seem to be able to just have a single rule specified:
tslint --config ./tslint.json --project ./tsconfig.json --fix
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With