Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upNew rule: no-nested-ternary #647
Comments
qzb
changed the title
New issue: no-nested-ternary
New rule: no-nested-ternary
Oct 3, 2016
This comment has been minimized.
This comment has been minimized.
|
I'm |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I use them too. Haven't run the numbers, but I suspect that this would break a lot of modules and the rule is not automatically fixable. |
feross
closed this
Oct 3, 2016
This comment has been minimized.
This comment has been minimized.
|
An example of where I have used nested ternary expressions would be in https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/src/bufferutils.js#L129-L134. function varIntSize (i) {
return i < 253 ? 1
: i < 0x10000 ? 3
: i < 0x100000000 ? 5
: 9
}I can't imagine how the use of a verbose set of |
dcousens
added
the
enhancement
label
Oct 3, 2016
This comment has been minimized.
This comment has been minimized.
|
On a devil's advocate note, Standard asks you to do this: a
? b
: c
? d
: eso it's a bit more readable: user.isAdmin() // if
? 'Manage' // then
: user.isEditor() // elseif
? 'Edit' // then
: 'Unauthorized' // else |
This comment has been minimized.
This comment has been minimized.
|
@rstacruz interesting, I find that less readable since in my head, chained ternary expressions are instead more like: if (a) return b
else if (c) return d
else return eYou wouldn't do if (a) return b
else if (c) return d
else return e |
qzb commentedOct 3, 2016
Disallow nested ternary expressions.
http://eslint.org/docs/rules/no-nested-ternary
Nested ternary expressions makes code really difficult to understand.