Skip to content

Commit a448ab6

Browse files
authored
Merge pull request #284 from github/unless-then-a-negation-breaks-my-brain
Seeing `unless !thing` breaks my brain
2 parents 4f80661 + 2c5b105 commit a448ab6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

STYLEGUIDE.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
This is GitHub's Ruby Style Guide, inspired by [RuboCop's guide][rubocop-guide].
44

55
## Table of Contents
6+
67
1. [Layout](#layout)
78
1. [Indentation](#indentation)
89
2. [Inline](#inline)
@@ -763,6 +764,22 @@ if x > 10
763764
end
764765
```
765766

767+
* Don't use `unless` with a negated condition.
768+
<a name="no-unless-negation"></a><sup>[[link](#no-unless-negation)]</sup>
769+
* <a href="https://docs.rubocop.org/rubocop/cops_style.html#stylenegatedunless">RuboCop rule: Style/NegatedUnless</a>
770+
771+
```ruby
772+
# bad
773+
unless !condition?
774+
do_something
775+
end
776+
777+
# good
778+
if condition?
779+
do_something
780+
end
781+
```
782+
766783
### Ternary operator
767784

768785
* Avoid the ternary operator (`?:`) except in cases where all expressions are extremely

config/default.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ Style/NegatedIfElseCondition:
13701370
Enabled: false
13711371

13721372
Style/NegatedUnless:
1373-
Enabled: false
1373+
Enabled: true
13741374

13751375
Style/NegatedWhile:
13761376
Enabled: false

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy