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 an error for Rails/FindBy when calling #first or #take on a Range object. #510

Merged
merged 1 commit into from
Jun 24, 2021
Merged

Fix an error for Rails/FindBy when calling #first or #take on a Range object. #510

merged 1 commit into from
Jun 24, 2021

Conversation

johnsyweb
Copy link
Contributor

Context

Upgrading rubocop-rails from 2.10.1 to 2.11.0 caused the following crash:

An error occurred while Rails/FindBy cop was inspecting /Users/paj/src/sso-server/app/models/username_suggestor.rb:63:6.
For /Users/paj/src/sso-server: configuration from /Users/paj/src/sso-server/.rubocop.yml
configuration from /Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.11.3/config/default.yml
configuration from /Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-performance-1.11.3/config/default.yml
Default configuration from /Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/config/default.yml
configuration from /Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.11.0/config/default.yml
configuration from /Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.11.0/config/default.yml
configuration from /Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-rspec-2.4.0/config/default.yml
configuration from /Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-rspec-2.4.0/config/default.yml
Inheriting configuration from /Users/paj/src/sso-server/.rubocop_todo.yml
Inspecting 1 file
Scanning /Users/paj/src/sso-server/app/models/username_suggestor.rb
undefined method `selector' for #<Parser::Source::Map::Collection:0x00007fe771ac68d0>
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-rails-2.11.0/lib/rubocop/cop/rails/find_by.rb:37:in `on_send'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:136:in `public_send'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:136:in `block (2 levels) in trigger_restricted_cops'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:160:in `with_cop_error_handling'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:135:in `block in trigger_restricted_cops'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:134:in `each'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:134:in `trigger_restricted_cops'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:159:in `block in on_send'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `each'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `each_with_index'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:156:in `on_send'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:71:in `on_send'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:154:in `on_def'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:71:in `on_def'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `block in on_dstr'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `each'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:137:in `on_dstr'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:71:in `on_begin'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:138:in `on_while'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:71:in `on_sclass'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:154:in `on_class'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:71:in `on_class'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-ast-1.7.0/lib/rubocop/ast/traversal.rb:20:in `walk'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/commissioner.rb:86:in `investigate'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/team.rb:155:in `investigate_partial'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:310:in `inspect_file'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:254:in `block in do_inspection_loop'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:288:in `block in iterate_until_no_changes'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:281:in `loop'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:281:in `iterate_until_no_changes'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:250:in `do_inspection_loop'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:130:in `block in file_offenses'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:155:in `file_offense_cache'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:129:in `file_offenses'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:120:in `process_file'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:100:in `each'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:100:in `reduce'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:100:in `each_inspected_file'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:86:in `inspect_files'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/runner.rb:47:in `run'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli.rb:72:in `execute_runners'
1 error occurred:
An error occurred while Rails/FindBy cop was inspecting /Users/paj/src/sso-server/app/models/username_suggestor.rb:63:6.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues

Mention the following information in the issue report:
1.17.0 (using Parser 3.0.1.1, rubocop-ast 1.7.0, running on ruby 2.7.3 x86_64-darwin19)

/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/lib/rubocop/cli.rb:41:in `run'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/exe/rubocop:12:in `block in <top (required)>'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.17.0/exe/rubocop:12:in `<top (required)>'
/Users/paj/.asdf/installs/ruby/2.7.3/bin/rubocop:23:in `load'
/Users/paj/.asdf/installs/ruby/2.7.3/bin/rubocop:23:in `<top (required)>'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/cli/exec.rb:63:in `load'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/cli/exec.rb:63:in `kernel_load'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/cli/exec.rb:28:in `run'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/cli.rb:474:in `exec'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/cli.rb:30:in `dispatch'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/cli.rb:24:in `start'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/exe/bundle:49:in `block in <top (required)>'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/lib/bundler/friendly_errors.rb:128:in `with_friendly_errors'
/Users/paj/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.2.20/exe/bundle:37:in `<top (required)>'
/Users/paj/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `load'
/Users/paj/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `<main>'
.

1 file inspected, no offenses detected
Finished in 0.6480320000555366 seconds

Change

  • Minimal working example
  • Fix failing spec
  • Extract #active_record?
  • Add spec for Range#first

Confirmation

  • 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 (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.
  • 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.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@koic
Copy link
Member

koic commented Jun 24, 2021

Good catch! Can you squash your commits into one?

- Minimal working example
- Fix failing spec
- Extract #where_method?
- Add spec for Range#first
@johnsyweb
Copy link
Contributor Author

Squashed into 3ed8153

@koic koic merged commit 9f6fcdc into rubocop:master Jun 24, 2021
@koic
Copy link
Member

koic commented Jun 24, 2021

Thanks!

@johnsyweb johnsyweb deleted the paj/bug-repro branch June 24, 2021 21:54
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