File tree Expand file tree Collapse file tree 2 files changed +22
-4
lines changed
packages/eslint-config-airbnb/rules Expand file tree Collapse file tree 2 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -1295,24 +1295,40 @@ Other Style Guides
1295
1295
eslint rules: [` no-nested-ternary` ](http: // eslint.org/docs/rules/no-nested-ternary.html).
1296
1296
1297
1297
` ` ` javascript
1298
- //bad
1298
+ // bad
1299
1299
const foo = maybe1 > maybe2
1300
1300
? "bar"
1301
1301
: value1 > value2 ? "baz" : null;
1302
1302
1303
- //better
1303
+ // better
1304
1304
const maybeNull = value1 > value2 ? 'baz' : null;
1305
1305
1306
1306
const foo = maybe1 > maybe2
1307
1307
? 'bar'
1308
1308
: maybeNull;
1309
1309
1310
- //best
1310
+ // best
1311
1311
const maybeNull = value1 > value2 ? 'baz' : null;
1312
1312
1313
1313
const foo = maybe1 > maybe2 ? 'bar' : maybeNull;
1314
1314
` ` `
1315
1315
1316
+ - [15.6 ](#15.6 ) < a name= ' 15.6' >< / a> Avoid unneeded ternary statements.
1317
+
1318
+ eslint rules: [` no-unneeded-ternary` ](http: // eslint.org/docs/rules/no-unneeded-ternary.html).
1319
+
1320
+ ` ` ` javascript
1321
+ // bad
1322
+ const foo = a ? a : b;
1323
+ const bar = c ? true : false;
1324
+ const baz = c ? false : true;
1325
+
1326
+ // good
1327
+ const foo = a || b;
1328
+ const bar = !!c;
1329
+ const baz = !c;
1330
+ ` ` `
1331
+
1316
1332
** [⬆ back to top](#table- of - contents)**
1317
1333
1318
1334
Original file line number Diff line number Diff line change @@ -74,7 +74,9 @@ module.exports = {
74
74
// disallow dangling underscores in identifiers
75
75
'no-underscore-dangle' : 0 ,
76
76
// disallow the use of Boolean literals in conditional expressions
77
- 'no-unneeded-ternary' : 0 ,
77
+ // also, prefer `a || b` over `a ? a : b`
78
+ // http://eslint.org/docs/rules/no-unneeded-ternary
79
+ 'no-unneeded-ternary' : [ 2 , { "defaultAssignment" : false } ] ,
78
80
// require padding inside curly braces
79
81
'object-curly-spacing' : [ 2 , 'always' ] ,
80
82
// allow just one var statement per function
You can’t perform that action at this time.
0 commit comments