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

Docs: clarify defaultAssignment option, fix no-unneeded-ternary examples #10874

Merged
merged 3 commits into from Sep 21, 2018
Merged
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
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