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 #7712] Fix an incorrect autocorrect for Style/OrAssignment #7720

Merged

Conversation

koic
Copy link
Member

@koic koic commented Feb 16, 2020

Fixes #7712.

This PR fixes an incorrect autocorrect for Style/OrAssignment when using elsif branch.

The following is a reproduction procedure.

% cat example.rb
foo = if foo
        foo
      elsif
        bar
      else
        'default'
      end

It is changed to the code with syntax error as follows.

% bundle exec rubocop -a --only Style/OrAssignment
(snip)

% cat example.rb
foo ||= elsif
          bar
        else
         'default'

% ruby -c example.rb
example.rb:1: syntax error, unexpected `elsif'
foo ||= elsif

The or assignment operator replaced when using elsif branch is complicated.
The PR will accept the above case without offense.


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.

@koic koic force-pushed the fix_incorrect_autocorrect_for_style_or_assignment branch 2 times, most recently from c05821c to 432291a Compare February 17, 2020 01:47
Fixes rubocop#7712.

This PR fixes an incorrect autocorrect for `Style/OrAssignment`
when using `elsif` branch.

The following is a reproduction procedure.

```ruby
% cat example.rb
foo = if foo
        foo
      elsif
        bar
      else
        'default'
      end
```

It is changed to the code with syntax error as follows.

```console
% bundle exec rubocop -a --only Style/OrAssignment
(snip)

% cat example.rb
foo ||= elsif
          bar
        else
         'default'

% ruby -c example.rb
example.rb:1: syntax error, unexpected `elsif'
foo ||= elsif
```

The or assignment operator replaced when using `elsif` branch is complicated.
The PR will accept the above case without offense.
@koic koic force-pushed the fix_incorrect_autocorrect_for_style_or_assignment branch from 432291a to de12994 Compare February 17, 2020 08:09
@bbatsov bbatsov merged commit 5400c1e into rubocop:master Feb 17, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 17, 2020

Thanks!

@koic koic deleted the fix_incorrect_autocorrect_for_style_or_assignment branch February 17, 2020 14:48
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.

-a --safe --only "Style/OrAssignment" introduces a syntax error
2 participants