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

[Fix #6738] Prevent auto-correct conflict of Style/Next and Style/SafeNavigation #7006

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 @@ -10,6 +10,7 @@
* [#6998](https://github.com/rubocop-hq/rubocop/pull/6998): Fix autocorrect of `Naming/RescuedExceptionsVariableName` to also rename all references to the variable. ([@Darhazer][])
* [#6992](https://github.com/rubocop-hq/rubocop/pull/6992): Fix unknown default configuration for `Layout/IndentFirstParameter` cop. ([@drenmi][])
* [#6972](https://github.com/rubocop-hq/rubocop/issues/6972): Fix a false positive for `Style/MixinUsage` when using inside block and `if` condition is after `include`. ([@koic][])
* [#6738](https://github.com/rubocop-hq/rubocop/issues/6738): Prevent auto-correct conflict of `Style/Next` and `Style/SafeNavigation`. ([@hoshinotsuyoshi][])
* [#6847](https://github.com/rubocop-hq/rubocop/pull/6847): Fix `Style/BlockDelimiters` to properly check if the node is chaned when `braces_for_chaining` is set. ([@att14][])

## 0.68.0 (2019-04-29)
Expand Down
4 changes: 4 additions & 0 deletions lib/rubocop/cop/style/next.rb
Expand Up @@ -54,6 +54,10 @@ class Next < Cop
MSG = 'Use `next` to skip iteration.'.freeze
EXIT_TYPES = %i[break return].freeze

def self.autocorrect_incompatible_with
[Style::SafeNavigation]
end

def investigate(_processed_source)
# When correcting nested offenses, we need to keep track of how much
# we have adjusted the indentation of each line
Expand Down
30 changes: 30 additions & 0 deletions spec/rubocop/cli/cli_autocorrect_spec.rb
Expand Up @@ -467,6 +467,36 @@ def verify_section
expect(IO.read('example.rb')).to eq(corrected)
end

it 'corrects Style/Next and Style/SafeNavigation offenses' do
create_file('.rubocop.yml', <<-YAML.strip_indent)
AllCops:
TargetRubyVersion: 2.3
YAML
source = <<-'RUBY'.strip_indent
until x
if foo
foo.some_method do
y
end
end
end
RUBY
create_file('example.rb', source)
expect(cli.run([
'--auto-correct',
'--only', 'Style/Next,Style/SafeNavigation'
])).to eq(0)
corrected = <<-'RUBY'.strip_indent
until x
next unless foo
foo.some_method do
y
end
end
RUBY
expect(IO.read('example.rb')).to eq(corrected)
end

it 'corrects `Lint/Lambda` and `Lint/UnusedBlockArgument` offenses' do
source = <<-'RUBY'.strip_indent
c = -> event do
Expand Down