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

Make FilePath check suffix when given a non-constant top-level node #1158

Merged

Conversation

topalovic
Copy link
Contributor

@topalovic topalovic commented Jun 9, 2021

Currently, RSpec/FilePath matcher ignores non-constant top-level nodes.

However, the standard feature format assumes string descriptions:

RSpec.feature "Some feature" do
end

This can make feature files without a proper suffix go unnoticed and then ignored by the runner. Test it by creating a feature file without a suffix, e.g. spec/features/some_feature.rb.

This PR makes the matcher more general by matching _ instead of const. If the top-level node is not a constant, we'll simply fall back to the basic spec_suffix_only? check, regardless of the actual config flag.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

@topalovic topalovic force-pushed the file-path-check-suffix-for-non-const branch from 4398429 to 7f542e3 Compare June 9, 2021 09:41
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @topalovic 👋

Looks good, thank you!

lib/rubocop/cop/rspec/file_path.rb Outdated Show resolved Hide resolved
@pirj pirj requested review from bquorning and Darhazer June 9, 2021 10:52
This helps with the standard feature format:

RSpec.feature "Some feature" do; end
@topalovic topalovic force-pushed the file-path-check-suffix-for-non-const branch from 7f542e3 to c4646ff Compare June 9, 2021 11:07
(block
$(send #rspec? _example_group $(const ...) $...) ...
$(send #rspec? _example_group $_ $...) ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we can capture just the arguments and deconstruct when needed

$(send #rspec? _example_group $_ $...)

then the usage will be

example_group(node) do |send_node, arguments|

and inside ensure_correct_file_path we would have

example_group, method_name, = *arguments

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it result in an internal affairs offence?

# lib/rubocop/cop/rspec/expect_output.rb
          # rubocop:disable InternalAffairs/NodeDestructuring
          variable_name, _rhs = *node
          # rubocop:enable InternalAffairs/NodeDestructuring

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only when the variable name ends with node 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I'm up to snuff wrt "internal affairs" or parser intricacies, so I would trust you to refactor the matcher according to your vision :-)

I'm primarily concerned with getting the fix out there, since my own team got burned by trusting RuboCop to warn about feature files without the suffix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm primarily concerned with getting the fix out there

It's released now, as v2.4.0.

@pirj
Copy link
Member

pirj commented Jun 9, 2021

I'm not sure why CircleCI doesn't pick up the build https://app.circleci.com/pipelines/github/rubocop/rubocop-rspec
Green locally with RuboCop 1.8.1 and Ruby 2.5.7.

@bquorning bquorning merged commit 2d00dbb into rubocop:master Jun 9, 2021
@topalovic topalovic deleted the file-path-check-suffix-for-non-const branch June 9, 2021 12:32
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.

4 participants