From 6d1ce3b6c58d1e775a60f55dcaee8c44a9784f7d Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Wed, 8 Sep 2021 01:12:42 +0900 Subject: [PATCH] Mark `Style/AndOr` as unsafe auto-correction This PR marks `Style/AndOr` as unsafe auto-correction. cf: https://github.com/rubocop/rubocop-rails/issues/210 --- .../change_mark_style_and_or_as_unsafe_auto_correction.md | 1 + config/default.yml | 3 ++- lib/rubocop/cop/style/and_or.rb | 4 ++++ spec/rubocop/cli/autocorrect_spec.rb | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelog/change_mark_style_and_or_as_unsafe_auto_correction.md diff --git a/changelog/change_mark_style_and_or_as_unsafe_auto_correction.md b/changelog/change_mark_style_and_or_as_unsafe_auto_correction.md new file mode 100644 index 00000000000..783e539ff46 --- /dev/null +++ b/changelog/change_mark_style_and_or_as_unsafe_auto_correction.md @@ -0,0 +1 @@ +* [#10068](https://github.com/rubocop/rubocop/pull/10068): Mark `Style/AndOr` as unsafe auto-correction. ([@koic][]) diff --git a/config/default.yml b/config/default.yml index 83f9f0f9b64..633034c71da 100644 --- a/config/default.yml +++ b/config/default.yml @@ -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: '<>' # Whether `and` and `or` are banned only in conditionals (conditionals) # or completely (always). EnforcedStyle: conditionals diff --git a/lib/rubocop/cop/style/and_or.rb b/lib/rubocop/cop/style/and_or.rb index 9cdc6ebd21c..35352912b88 100644 --- a/lib/rubocop/cop/style/and_or.rb +++ b/lib/rubocop/cop/style/and_or.rb @@ -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 diff --git a/spec/rubocop/cli/autocorrect_spec.rb b/spec/rubocop/cli/autocorrect_spec.rb index 565b2464291..dfb03df71bb 100644 --- a/spec/rubocop/cli/autocorrect_spec.rb +++ b/spec/rubocop/cli/autocorrect_spec.rb @@ -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)