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

Detect require block passed as argument in Lint/NonDeterministicRequireOrder #8279

Merged
merged 3 commits into from Jul 13, 2020

Conversation

biinari
Copy link
Contributor

@biinari biinari commented Jul 8, 2020

Detect &method(:require) passed as a block argument. For example:

Dir[Rails.root.join('spec/support/**/*.rb')].each(&method(:require))

Dir.glob(
  Rails.root.join('spec', 'support', '**', '*.rb'),
  &method(:require)
)

These are examples from our code base where the non-deterministic require order was not picked up.

Notes

I originally tried adding on_send handler for this but that had problems:

  • Reaching the correct level of node for the different forms (Dir.glob(...) vs Dir[...].each).
  • Detecting whether the block is passed as an argument.
  • The cop would then have to look at much more code.

Some pending specs for this leaked in via #8245 without description, sorry about that.


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.

Detect `&method(:require)` passed as a block argument. For example:

```ruby
Dir[Rails.root.join('spec/support/**/*.rb')].each(&method(:require))

Dir.glob(
  Rails.root.join('spec', 'support', '**', '*.rb'),
  &method(:require)
)
```
@biinari biinari force-pushed the feature/require_order_block_pass branch from 174e937 to 739afb6 Compare July 8, 2020 21:13
@bbatsov bbatsov merged commit 18e318f into rubocop:master Jul 13, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 13, 2020

Thanks!

@biinari biinari deleted the feature/require_order_block_pass branch August 7, 2020 21:44
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.

None yet

2 participants