Skip to content

Commit

Permalink
Change enforced style to conditionals for Style/AndOr
Browse files Browse the repository at this point in the history
This PR changes enforced style to `conditionals` for `Style/AndOr` cop.
It forward porting from rubocop/rubocop-rails#224.
  • Loading branch information
koic authored and bbatsov committed May 12, 2020
1 parent 5df717c commit 9731d67
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -9,6 +9,7 @@
### Changes

* [#7952](https://github.com/rubocop-hq/rubocop/pull/7952): **(Breaking)** Change the max line length of `Layout/LineLength` to 120 by default. ([@koic][])
* [#7959](https://github.com/rubocop-hq/rubocop/pull/7959): Change enforced style to conditionals for `Style/AndOr`. ([@koic][])

## 0.83.0 (2020-05-11)

Expand Down
2 changes: 1 addition & 1 deletion config/default.yml
Expand Up @@ -2274,7 +2274,7 @@ Style/AndOr:
VersionChanged: '0.25'
# Whether `and` and `or` are banned only in conditionals (conditionals)
# or completely (always).
EnforcedStyle: always
EnforcedStyle: conditionals
SupportedStyles:
- always
- conditionals
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/style/and_or.rb
Expand Up @@ -7,7 +7,7 @@ module Style
# `||` instead. It can be configured to check only in conditions or in
# all contexts.
#
# @example EnforcedStyle: always (default)
# @example EnforcedStyle: always
# # bad
# foo.save and return
#
Expand All @@ -22,7 +22,7 @@ module Style
# if foo && bar
# end
#
# @example EnforcedStyle: conditionals
# @example EnforcedStyle: conditionals (default)
# # bad
# if foo and bar
# end
Expand Down
6 changes: 3 additions & 3 deletions manual/cops_style.md
Expand Up @@ -139,7 +139,7 @@ all contexts.

### Examples

#### EnforcedStyle: always (default)
#### EnforcedStyle: always

```ruby
# bad
Expand All @@ -156,7 +156,7 @@ foo.save && return
if foo && bar
end
```
#### EnforcedStyle: conditionals
#### EnforcedStyle: conditionals (default)

```ruby
# bad
Expand All @@ -178,7 +178,7 @@ end

Name | Default value | Configurable values
--- | --- | ---
EnforcedStyle | `always` | `always`, `conditionals`
EnforcedStyle | `conditionals` | `always`, `conditionals`

### References

Expand Down
18 changes: 11 additions & 7 deletions spec/rubocop/cli_spec.rb
Expand Up @@ -507,7 +507,11 @@ def and_with_args

context 'via the config' do
before do
create_file('example.rb', 'do_something or raise')
create_file('example.rb', <<~RUBY)
if foo and bar
do_something
end
RUBY
create_file('.rubocop.yml', <<~YAML)
AllCops:
StyleGuideCopsOnly: #{guide_cops_only}
Expand Down Expand Up @@ -548,10 +552,10 @@ def and_with_args

expect($stdout.string).to eq(<<~RESULT)
1 Layout/LineLength
3 Layout/LineLength
1 Style/AndOr
--
2 Total
4 Total
RESULT
end
Expand All @@ -569,9 +573,9 @@ def and_with_args

expect($stdout.string).to eq(<<~RESULT)
1 Layout/LineLength
3 Layout/LineLength
--
1 Total
3 Total
RESULT
end
Expand All @@ -585,10 +589,10 @@ def and_with_args

expect($stdout.string).to eq(<<~RESULT)
1 Layout/LineLength
3 Layout/LineLength
1 Style/AndOr
--
2 Total
4 Total
RESULT
end
Expand Down

0 comments on commit 9731d67

Please sign in to comment.