ESLint plugin to disallow unary + operators.
The unary + operator can be used on any type and converts it to a number. As a result, a plus before any value is valid javascript code and unintentional + operators can be hard to find. This is especially troublesome with string concatenation over several lines:
const str = "Concatenating several strings " +
+ "can be dangerous " + "because having more than one " +
"+ " + + "between the strings " + "leads to conversions to " +
+ "numbers.";
console.log(str);
Results in:
Concatenating several strings NaNbecause having more than one + NaNleads to conversions to NaN
Install plugin npm:
$ npm install eslint-plugin-no-unary-plus --save-dev
Add plugin and rule in .eslintrc
:
{
"plugins": [
...
"no-unary-plus",
...
],
...
"rules": {
...
"no-unary-plus/no-unary-plus": "error",
...
}
}