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

Style/MissingElse crash #1705

Closed
gerry3 opened this issue Mar 10, 2015 · 0 comments
Closed

Style/MissingElse crash #1705

gerry3 opened this issue Mar 10, 2015 · 0 comments

Comments

@gerry3
Copy link
Contributor

gerry3 commented Mar 10, 2015

I'm using master - 0.29.1 (using Parser 2.2.0.3, running on ruby 2.2.0 x86_64-darwin14)

The Style/MissingElse cop causes the offense report to crash:

<file>.rb:9:5: C: if condition requires an else-clause.
undefined method `source_line' for #<Parser::Source::Map::Condition:0x007fde525c2140>
<path>/.rvm/gems/ruby-2.2.0@<gemset>/bundler/gems/rubocop-f52bc7e2ec4b/lib/rubocop/formatter/clang_style_formatter.rb:15:in `block in report_file'

The fix seems to be to pass :expression as the second argument to add_offense (instead of node.location). I will submit a PR with the fix soon.

I noticed that when an exception occurs during inspection, it's caught and a message is displayed (An error occurred while <cop> cop was inspecting <file>.). Should something similar be done during reporting? Or is there another way we could catch an issue like this ahead of time? Is there a type of spec that tests reporting missing for this cop?

bbatsov added a commit that referenced this issue Mar 19, 2015
[Fix #1705] MissingElse: pass correct loc to add_offense
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

No branches or pull requests

1 participant