Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Add explicit default option always for eqeqeq (refs #6144) #6342

Merged
merged 1 commit into from Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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