diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b6bd14c5a2..5abc4c3d706 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/config/default.yml b/config/default.yml index a5bff430fe8..15a2796d399 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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 diff --git a/lib/rubocop/cop/style/and_or.rb b/lib/rubocop/cop/style/and_or.rb index 0ee839a1c81..87c0f156a49 100644 --- a/lib/rubocop/cop/style/and_or.rb +++ b/lib/rubocop/cop/style/and_or.rb @@ -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 # @@ -22,7 +22,7 @@ module Style # if foo && bar # end # - # @example EnforcedStyle: conditionals + # @example EnforcedStyle: conditionals (default) # # bad # if foo and bar # end diff --git a/manual/cops_style.md b/manual/cops_style.md index 4a831c631fe..8a24e211106 100644 --- a/manual/cops_style.md +++ b/manual/cops_style.md @@ -139,7 +139,7 @@ all contexts. ### Examples -#### EnforcedStyle: always (default) +#### EnforcedStyle: always ```ruby # bad @@ -156,7 +156,7 @@ foo.save && return if foo && bar end ``` -#### EnforcedStyle: conditionals +#### EnforcedStyle: conditionals (default) ```ruby # bad @@ -178,7 +178,7 @@ end Name | Default value | Configurable values --- | --- | --- -EnforcedStyle | `always` | `always`, `conditionals` +EnforcedStyle | `conditionals` | `always`, `conditionals` ### References diff --git a/spec/rubocop/cli_spec.rb b/spec/rubocop/cli_spec.rb index 206ab56cd75..2e15cfbc1a9 100644 --- a/spec/rubocop/cli_spec.rb +++ b/spec/rubocop/cli_spec.rb @@ -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} @@ -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 @@ -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 @@ -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