eslint/eslint — pull request #1570 by btmills (2014-12-11 02:40:48+00:00)
Title: Update: add yoda exception for "between" tests (fixes #1561)

This is a possible implementation of #1561 to see whether it's worth pursuing. This is the most restrictive version I could imagine being reasonable, on the assumption that we can drop restrictions if it's too complex. In order to qualify for the exception, a BinaryExpression's parent must be:

- An `&&` `LogicalExpression`...
- ...containing two `BinaryExpression`s...
- ...whose tests are both `<` or `<=`...
- ...with two literals describing a range on the outside...
- ...with the same member expression or identifier on the interior...
- ...that is wrapped in parens.

For example:

- `var a = 0 < b && b < 1 ? "between" : "outside";` would fail, but `var a = (0 < b && b < 1) ? "between" : "outside";` would pass.
- `if (1 <= x && x < 0) {}` makes no sense, so it would fail, but `if (0 <= x && x < 1) {}` would pass.
- `if (a < 1 && 1 < x && x < 10) {}` would fail, but wrapping it in parens `if (a < 1 && (a < x && x < 10)) {}` would let it pass.
- Neither "outside" tests `if (x < 6 || 8 < x) {}` nor "backwards" tests `if (6 > x && x > 5) {}` are included in this exception.