Skip to content

Commit

Permalink
Merge pull request airbnb#115 from airbnb/kmsun07-patch-1
Browse files Browse the repository at this point in the history
Add rule discouraging `unless` with comparators
  • Loading branch information
Kevin Sun authored May 2, 2017
2 parents 9c9085f + e1c58c1 commit 01da1fb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,30 @@ In either case:
end
```

* <a name="unless-with-comparator"></a>Avoid `unless` with comparators if you can use `if` with an opposing comparator.<sup>[[link](#unless-with-comparator)]</sup>

```ruby
# bad
unless x == 10
...
end
# good
if x != 10
...
end
# bad
unless x < 10
...
end
# good
if x >= 10
...
end
```

* <a name="parens-around-conditions"></a>Don't use parentheses around the
condition of an `if/unless/while`.
<sup>[[link](#parens-around-conditions)]</sup>
Expand Down

0 comments on commit 01da1fb

Please sign in to comment.