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

Mark Style/AndOr as unsafe auto-correction #10068

Merged
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
@@ -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