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

Conversation

hoshinotsuyoshi
Copy link
Contributor

Fixes #6738

Solves problem like below:

problem

until x
  if foo
    foo.some_method do
      y
    end
  end
end

auto-corrects badly;

# frozen_string_literal: true

until x
  next unless foofoo&.some_method do
    y
  end
end

( in rubocop.yml, TargetRubyVersion: 2.3 needed(2.3 or higher version). )

new behavior

auto-corrects:

# frozen_string_literal: true

until x
  next unless foo

  foo.some_method do
    y
  end
end

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

hoshinotsuyoshi and others added 2 commits April 30, 2019 18:35
…`Style/SafeNavigation`

Fixes rubocop#6738

Solves problem like below:

  ```ruby
  until x
    if foo
      foo.some_method do
        y
      end
    end
  end
  ```

  auto-corrects badly;

  ```ruby
  # frozen_string_literal: true

  until x
    next unless foofoo&.some_method do
      y
    end
  end
  ```
@bbatsov bbatsov merged commit 36673f0 into rubocop:master Apr 30, 2019
@hoshinotsuyoshi hoshinotsuyoshi deleted the autocorrect_conflict_next_and_safe_navigation branch May 4, 2019 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autocorrect for Style/SafeNavigation or/with Style/Next breaks code
2 participants