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

Rails/UniqueValidationWithoutIndex undefined method error #356

Closed
dteoh opened this issue Sep 15, 2020 · 2 comments
Closed

Rails/UniqueValidationWithoutIndex undefined method error #356

dteoh opened this issue Sep 15, 2020 · 2 comments
Labels
duplicate This issue or pull request already exists

Comments

@dteoh
Copy link

dteoh commented Sep 15, 2020

$ bin/rubocop --only Rails/UniqueValidationWithoutIndex -d app/models/concerns/some_concern.rb
For /Users/dteoh/dev/some_project: configuration from /Users/dteoh/dev/some_project/.rubocop.yml
configuration from /Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-performance-1.8.0/config/default.yml
configuration from /Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-performance-1.8.0/config/default.yml
Default configuration from /Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/config/default.yml
configuration from /Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/config/default.yml
configuration from /Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/config/default.yml
Inspecting 1 file
Scanning /Users/dteoh/dev/some_project/app/models/concerns/some_concern.rb
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /Users/dteoh/dev/some_project/app/models/concerns/some_concern.rb:8:4.
undefined method `each_node' for nil:NilClass
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/lib/rubocop/cop/mixin/active_record_helper.rb:14:in `find_set_table_name'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/lib/rubocop/cop/mixin/active_record_helper.rb:35:in `each'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/lib/rubocop/cop/mixin/active_record_helper.rb:35:in `to_a'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/lib/rubocop/cop/mixin/active_record_helper.rb:35:in `table_name'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/lib/rubocop/cop/rails/unique_validation_without_index.rb:49:in `find_schema_information'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-rails-2.8.0/lib/rubocop/cop/rails/unique_validation_without_index.rb:38:in `on_send'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:99:in `block (2 levels) in trigger_responding_cops'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:152:in `with_cop_error_handling'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:98:in `block in trigger_responding_cops'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:97:in `each'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:97:in `trigger_responding_cops'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:70:in `on_send'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:173:in `on_block'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:72:in `on_block'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:59:in `block in on_begin'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:59:in `each'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:59:in `on_begin'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:72:in `on_begin'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:159:in `on_while'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:72:in `on_module'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-ast-0.4.0/lib/rubocop/ast/traversal.rb:14:in `walk'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/commissioner.rb:85:in `investigate'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/team.rb:152:in `investigate_partial'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cop/team.rb:83:in `investigate'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:296:in `inspect_file'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:246:in `block in do_inspection_loop'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:278:in `block in iterate_until_no_changes'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:271:in `loop'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:271:in `iterate_until_no_changes'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:242:in `do_inspection_loop'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:122:in `block in file_offenses'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:147:in `file_offense_cache'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:121:in `file_offenses'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:112:in `process_file'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:91:in `block in each_inspected_file'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:90:in `each'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:90:in `reduce'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:90:in `each_inspected_file'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:79:in `inspect_files'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/runner.rb:40:in `run'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cli/command/execute_runner.rb:22:in `execute_runner'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cli/command/execute_runner.rb:14:in `run'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cli/command.rb:11:in `run'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cli/environment.rb:18:in `run'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/lib/rubocop/cli.rb:41:in `run'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/exe/rubocop:13:in `block in <top (required)>'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/Users/dteoh/.asdf/installs/ruby/2.5.5/lib/ruby/gems/2.5.0/gems/rubocop-0.90.0/exe/rubocop:12:in `<top (required)>'
bin/rubocop:29:in `load'
bin/rubocop:29:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/UniqueValidationWithoutIndex cop was inspecting /Users/dteoh/dev/some_project/app/models/concerns/some_concern.rb:8:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Expected behavior

Ignore the module, or somehow apply the check in the context of the class that includes the module.

Actual behavior

Error occured.

Disabling the check does not work.

Steps to reproduce the problem

Module triggering the bug:

# app/models/concerns/some_concern.rb

# frozen_string_literal: true

# A test concern to trigger RuboCop bug.
module SomeConcern
  extend ActiveSupport::Concern

  included do
    validates :a_column, uniqueness: true
  end
end

RuboCop version

0.90.0 (using Parser 2.7.1.4, rubocop-ast 0.4.0, running on ruby 2.5.5 x86_64-darwin19)
@koic koic transferred this issue from rubocop/rubocop Sep 15, 2020
@koic koic added the duplicate This issue or pull request already exists label Sep 15, 2020
@koic
Copy link
Member

koic commented Sep 15, 2020

Dup with #348. Can you upgrade to the latest RuboCop Rails?
Thank you.

@koic koic closed this as completed Sep 15, 2020
@dteoh
Copy link
Author

dteoh commented Sep 15, 2020

Thank you, error has disappeared.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants