Skip to content

Commit

Permalink
Mark Style/AndOr as unsafe auto-correction
Browse files Browse the repository at this point in the history
This PR marks `Style/AndOr` as unsafe auto-correction.

cf: rubocop/rubocop-rails#210
  • Loading branch information
koic committed Sep 8, 2021
1 parent 27f2c59 commit 7d45c0d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
@@ -0,0 +1 @@
* [#10068](https://github.com/rubocop/rubocop/pull/10068): Mark `Style/AndOr` as unsafe auto-correction. ([@koic][])
3 changes: 2 additions & 1 deletion config/default.yml
Expand Up @@ -2802,8 +2802,9 @@ Style/AndOr:
Description: 'Use &&/|| instead of and/or.'
StyleGuide: '#no-and-or-or'
Enabled: true
SafeAutoCorrect: false
VersionAdded: '0.9'
VersionChanged: '0.25'
VersionChanged: '<<next>>'
# Whether `and` and `or` are banned only in conditionals (conditionals)
# or completely (always).
EnforcedStyle: conditionals
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/style/and_or.rb
Expand Up @@ -7,6 +7,10 @@ module Style
# `||` instead. It can be configured to check only in conditions or in
# all contexts.
#
# It is marked as unsafe auto-correction because it may change the
# operator precedence between logical operators (`&&` and `||`) and
# semantic operators (`and` and `or`).
#
# @example EnforcedStyle: always
# # bad
# foo.save and return
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cli/autocorrect_spec.rb
Expand Up @@ -271,7 +271,7 @@ def batch
end
RUBY
expect(
cli.run(['--auto-correct', '--only', 'Style/MethodCallWithArgsParentheses,Style/AndOr'])
cli.run(['--auto-correct-all', '--only', 'Style/MethodCallWithArgsParentheses,Style/AndOr'])
).to eq(0)
expect(File.read('example.rb')).to eq(<<~RUBY)
if foo && bar(:arg)
Expand Down

0 comments on commit 7d45c0d

Please sign in to comment.