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 #9333] Fix an error for Style/IfInsideElse #9334

Merged
merged 1 commit into from
Jan 5, 2021

Conversation

koic
Copy link
Member

@koic koic commented Jan 5, 2021

Fixes #9333.

This PR fixes an error for Style/IfInsideElse when using a modifier if nested inside an else after elsif.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

Fixes rubocop#9333.

This PR fixes an error for `Style/IfInsideElse`
when using a modifier `if` nested inside an `else` after `elsif`.
@koic koic force-pushed the fix_an_error_for_style_if_inside_else branch from 7f95f1e to f7edb18 Compare January 5, 2021 02:42
@bbatsov bbatsov merged commit e2718b4 into rubocop:master Jan 5, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Jan 5, 2021

Thanks!

@koic koic deleted the fix_an_error_for_style_if_inside_else branch January 5, 2021 06:32
@joshbuker
Copy link

Still running into this error, although I thought my version locks should be up-to-date, and I just ran bundle update before running rubocop...

An error occurred while Style/IfInsideElse cop was inspecting [REDACTED].
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
1.7.0 (using Parser 2.7.2.0, rubocop-ast 1.4.1, running on ruby 2.7.2 x86_64-linux)

Is this fix live?

@koic
Copy link
Member Author

koic commented Jun 30, 2021

@athix Thank you for your feedback. This patch has been released, but there may still be issues with that error. Can you provide a reproduction code?

@joshbuker
Copy link

I think I fixed it by just doing some cleanup of the code, IIRC what was breaking was something along the lines of:

if cond
  code_here
elsif cond2
  other_code_here
else
  another_code_here if cond3
end

Which changing to this potentially fixed it:

if cond
  code_here
elsif cond2
  other_code_here
elsif cond3
  another_code_here
end

I could look at the git diff and give you a concrete example though if that would be helpful.

Basically I got it to stop erroring by cleaning up the code a bit. There were a couple spots that I could see causing the parser a hard time, so I'm not 100% on if it was that change, or another change I did at the same time.

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.

Style/IfInsideElse error: undefined method `last_line' for nil:NilClass
3 participants