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 RSpec/FilePath when checking an empty class #1000
Conversation
Remember that `RSpec/FilePath` checks *all* files - not only **/*_spec.rb. And when some class defines e.g. an empty class, the `TopLevelGroup` module would raise an error. Fixes #999.
RSpec/FilePath
when checking an empty class
Congratulations on the 1K pull requests (and issues) 🎉 |
I hope it’s OK to ignore Code Climate’s report on added complexity… |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have spec/smoke_tests/empty_spec.rb
. How did it happen to pass?
@@ -204,6 +204,14 @@ | |||
RUBY | |||
end | |||
|
|||
# RSpec/FilePath runs on all files - not only **/*_spec.rb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering, why so?
For some reason relevant_rubocop_rspec_file?
evaluates to true
for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see it
def relevant_rubocop_rspec_file?(_file)
true
end
@@ -38,7 +38,9 @@ def top_level_group?(node) | |||
end | |||
|
|||
def top_level_nodes(node) | |||
if node.begin_type? | |||
if node.nil? | |||
[] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember we were discussing this with Maxim and settled on
return unless root_node
Do you think both checks are necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you mention, we already have return unless root_node
inside #on_new_investigation
. The problem happens when the root node is an empty module or class:
elsif node.module_type? || node.class_type?
top_level_nodes(node.body)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, we could move the check into the elsif
body:
elsif node.module_type? || node.class_type?
node.body.nil? ? [] : top_level_nodes(node.body)
or
elsif node.module_type? || node.class_type?
if node.body
top_level_nodes(node.body)
else
[]
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Look good!
Remember that
RSpec/FilePath
checks all files - not only **/*_spec.rb. And when some class defines e.g. an empty class, theTopLevelGroup
module would raise an error.Fixes #999.
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).