Skip to content

Commit

Permalink
Docs: clarify defaultAssignment option, fix no-unneeded-ternary examp…
Browse files Browse the repository at this point in the history
…les (#10874)

* Contradictions in no-unneeded-ternary documentation

See #10872

* Updated examples to more clearly reflect eslint behaviour.

* Update no-unneeded-ternary.md
  • Loading branch information
CoffeeTableEspresso authored and platinumazure committed Sep 21, 2018
1 parent 9d52541 commit a6ebfd3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions docs/rules/no-unneeded-ternary.md
Expand Up @@ -23,10 +23,10 @@ Here is an example:

```js
// Bad
var foo = bar ? bar : 1;
foo(bar ? bar : 1);

// Good
var foo = bar || 1;
foo(bar || 1);
```

## Rule Details
Expand All @@ -41,6 +41,8 @@ Examples of **incorrect** code for this rule:
var a = x === 2 ? true : false;

var a = x ? true : false;

var a = f(x ? x : 1);
```

Examples of **correct** code for this rule:
Expand All @@ -56,7 +58,7 @@ var a = x ? "Yes" : "No";

var a = x ? y : x;

var a = x ? x : 1;
var a = x ? x : 1; // Note that this is only allowed as it on the right hand side of an assignment; this type of ternary is disallowed everywhere else. See defaultAssignment option below for more details.
```

## Options
Expand All @@ -68,6 +70,8 @@ This rule has an object option:

### defaultAssignment

The defaultAssignment option allows expressions of the form `x ? x : expr` (where `x` is any identifier and `expr` is any expression) as the right hand side of assignments (but nowhere else).

Examples of additional **incorrect** code for this rule with the `{ "defaultAssignment": false }` option:

```js
Expand Down

0 comments on commit a6ebfd3

Please sign in to comment.