Skip to content

Commit

Permalink
Update: Add explicit default option always for eqeqeq (refs #6144) (
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto authored and nzakas committed Jun 10, 2016
1 parent 2d63370 commit 54c30fb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
38 changes: 38 additions & 0 deletions docs/rules/eqeqeq.md
Expand Up @@ -29,6 +29,44 @@ if (obj.getStuff() != undefined) { }

## Options

### always

The `"always"` option (default) enforces the use of `===` and `!==` in every situation.

Examples of **incorrect** code for the `"always"` option:

```js
/*eslint eqeqeq: ["error", "always"]*/

a == b
foo == true
bananas != 1
value == undefined
typeof foo == 'undefined'
'hello' != 'world'
0 == 0
true == true
foo == null

```

Examples of **correct** code for the `"always"` option:

```js
/*eslint eqeqeq: ["error", "always"]*/

a === b
foo === true
bananas !== 1
value === undefined
typeof foo === 'undefined'
'hello' !== 'world'
0 === 0
true === true
foo === null

```

### smart

The `"smart"` option enforces the use of `===` and `!==` except for these cases:
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/eqeqeq.js
Expand Up @@ -19,7 +19,7 @@ module.exports = {

schema: [
{
enum: ["smart", "allow-null"]
enum: ["always", "smart", "allow-null"]
}
]
},
Expand Down
5 changes: 5 additions & 0 deletions tests/lib/rules/eqeqeq.js
Expand Up @@ -22,6 +22,7 @@ ruleTester.run("eqeqeq", rule, {
valid: [
"a === b",
"a !== b",
{ code: "a === b", options: ["always"] },
{ code: "typeof a == 'number'", options: ["smart"] },
{ code: "'string' != typeof a", options: ["smart"] },
{ code: "'hello' != 'world'", options: ["smart"] },
Expand All @@ -36,11 +37,15 @@ ruleTester.run("eqeqeq", rule, {
{ code: "a == b", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "a != b", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression"}] },
{ code: "typeof a == 'number'", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "typeof a == 'number'", options: ["always"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "'string' != typeof a", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression"}] },
{ code: "true == true", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "2 == 3", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "2 == 3", options: ["always"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "'hello' != 'world'", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression"}] },
{ code: "'hello' != 'world'", options: ["always"], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression"}] },
{ code: "a == null", errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "a == null", options: ["always"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "null != a", errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression"}] },
{ code: "true == 1", options: ["smart"], errors: [{ message: "Expected '===' and instead saw '=='.", type: "BinaryExpression"}] },
{ code: "0 != '1'", options: ["smart"], errors: [{ message: "Expected '!==' and instead saw '!='.", type: "BinaryExpression"}] },
Expand Down

0 comments on commit 54c30fb

Please sign in to comment.