diff --git a/docs/rules/no-unneeded-ternary.md b/docs/rules/no-unneeded-ternary.md index b2a6b0281dd..b4caddf5855 100644 --- a/docs/rules/no-unneeded-ternary.md +++ b/docs/rules/no-unneeded-ternary.md @@ -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 @@ -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: @@ -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 @@ -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