Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change enforced style to conditionals for Style/AndOr #7959

Merged
merged 1 commit into from May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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