Enforce JS var declaration with value

This caught us out recently where code did a strict type check for `myVar === undefined`.
The var was defined as `let myVar;`, without a value - so the check returned false (it's `null`).
To avoid this situation, we've decided to enforce declarations with values.
Note that preference should be given to single, immutable assignments via const where possible.

See http://eslint.org/docs/rules/init-declarations
This commit is contained in:
Ingo Schommer 2016-09-13 10:08:32 +12:00
parent 4b5dd99245
commit ff4336010c
1 changed files with 4 additions and 1 deletions

View File

@ -1,3 +1,6 @@
{
"extends": "airbnb"
"extends": "airbnb",
"rules": {
"init-declarations": 1
}
}