0.3.1 • Published 7 months ago

eslint-plugin-no-unary-plus v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

ESLint plugin to disallow unary + operators.

The Problem with the Unary Plus

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

Usage

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",
    ...
  }
}
0.3.1

7 months ago

0.3.0

7 months ago

0.2.0

7 months ago

0.1.0

7 months ago