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

v0.67.2: An error occurred while Rails/ActiveRecordOverride cop was inspecting #6888

Closed
rjurado01 opened this issue Apr 5, 2019 · 7 comments · Fixed by #6889
Closed

v0.67.2: An error occurred while Rails/ActiveRecordOverride cop was inspecting #6888

rjurado01 opened this issue Apr 5, 2019 · 7 comments · Fixed by #6889

Comments

@rjurado01
Copy link

Expected behavior

Works without error.

Actual behavior

When run rubocop in this model:

# app/models/group.rb

class Group
  def self.create(attributes)
  end

  def update(attributes)
  end
end

Throw this error:

An error occurred while Rails/ActiveRecordOverride cop was inspecting /home/rjurado/.../app/models/group.rb:8:2.
undefined method `const_name' for nil:NilClass
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/rails/active_record_override.rb:42:in `on_def'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `each'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `each'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:92:in `on_class'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:13:in `walk'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:46:in `investigate'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:116:in `investigate'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:104:in `offenses'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:44:in `inspect_file'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:273:in `inspect_file'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:220:in `block in do_inspection_loop'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:252:in `block in iterate_until_no_changes'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `loop'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `iterate_until_no_changes'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:216:in `do_inspection_loop'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:119:in `block in file_offenses'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:137:in `file_offense_cache'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:117:in `file_offenses'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:105:in `process_file'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:82:in `block in each_inspected_file'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `reduce'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each_inspected_file'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:73:in `inspect_files'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:39:in `run'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:174:in `execute_runner'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:75:in `execute_runners'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:47:in `run'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/exe/rubocop:25:in `block in <top (required)>'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/home/rjurado/.asdf/installs/ruby/2.5.3/lib/ruby/gems/2.5.0/gems/rubocop-0.67.2/exe/rubocop:24:in `<top (required)>'
/home/rjurado/.asdf/installs/ruby/2.5.3/bin/rubocop:23:in `load'
/home/rjurado/.asdf/installs/ruby/2.5.3/bin/rubocop:23:in `<main>'

Steps to reproduce the problem

Just running rubocop in app/models folder of my Rails project.

RuboCop version

0.67.2 (using Parser 2.6.0.0, running on ruby 2.5.3 x86_64-linux)
@rjurado01 rjurado01 changed the title 0.67.2: An error occurred while Rails/ActiveRecordOverride cop was inspecting v0.67.2: An error occurred while Rails/ActiveRecordOverride cop was inspecting Apr 5, 2019
@pdobb
Copy link
Contributor

pdobb commented Apr 8, 2019

I ran into this same issue. It looks like the fix from @diachini will solve this one too, but wanted to point out that I saw a similar error on a class that uses module_function:

Create a PORO class with a save method below the module_function macro.

Saved in Rails app at: app/models/app/console.rb

# frozen_string_literal: true

module App
  module Console
    module_function  # Must exist

    def save
    end
  end
end

Failure details:

$ rubocop app/models/app/console.rb -d
For /Users/pauld/dev/badger: configuration from /Users/pauld/dev/badger/.rubocop.yml
Inheriting configuration from /Users/pauld/dev/badger/.rubocop_todo.yml
Default configuration from /Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/config/default.yml
Inspecting 1 file
Scanning /Users/pauld/dev/badger/app/models/app/console.rb
An error occurred while Rails/ActiveRecordOverride cop was inspecting /Users/pauld/dev/badger/app/models/app/console.rb:7:4.
undefined method `const_name' for nil:NilClass
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/rails/active_record_override.rb:42:in `on_def'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `each'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `each'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `on_begin'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:150:in `on_while'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:150:in `on_while'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:13:in `walk'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:46:in `investigate'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:116:in `investigate'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:104:in `offenses'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:44:in `inspect_file'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:273:in `inspect_file'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:220:in `block in do_inspection_loop'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:252:in `block in iterate_until_no_changes'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `loop'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `iterate_until_no_changes'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:216:in `do_inspection_loop'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:119:in `block in file_offenses'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:137:in `file_offense_cache'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:117:in `file_offenses'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:105:in `process_file'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:82:in `block in each_inspected_file'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `reduce'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each_inspected_file'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:73:in `inspect_files'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/runner.rb:39:in `run'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cli.rb:174:in `execute_runner'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cli.rb:75:in `execute_runners'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cli.rb:47:in `run'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/exe/rubocop:25:in `block in <top (required)>'
/Users/pauld/.rubies/ruby-2.5.3/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/Users/pauld/.gem/ruby/2.5.3/gems/rubocop-0.67.2/exe/rubocop:24:in `<top (required)>'
/Users/pauld/.gem/ruby/2.5.3/bin/rubocop:23:in `load'
/Users/pauld/.gem/ruby/2.5.3/bin/rubocop:23:in `<main>'
C

Offenses:

app/models/app/console.rb:4:3: C: Style/Documentation: Missing top-level module documentation comment.
  module Console
  ^^^^^^

1 file inspected, 1 offense detected

1 error occurred:
An error occurred while Rails/ActiveRecordOverride cop was inspecting /Users/pauld/dev/badger/app/models/app/console.rb:7:4.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

RuboCop version

0.67.2 (using Parser 2.6.2.1, running on ruby 2.5.3 x86_64-darwin18)

@ghost
Copy link

ghost commented Apr 10, 2019

Similar issue here when running Rubocop against the following code:

# app/models/transaction.rb
class Transaction
  def destroy
  end

  private
end

Note: issue won't happen when private isn't present.

Error:

An error occurred while Rails/ActiveRecordOverride cop was inspecting app/models/transaction.rb:2:2.
undefined method `const_name' for nil:NilClass

@veganstraightedge
Copy link

Same problem for us too.

crimethinc/website#1099

https://travis-ci.org/crimethinc/website/builds/518080309

File in question:

https://github.com/crimethinc/website/blob/master/app/models/advanced_search.rb

crimethinc/website/app/models/advanced_search.rb
An error occurred while Rails/ActiveRecordOverride cop was inspecting /crimethinc/website/app/models/advanced_search.rb:8:2.
undefined method `const_name' for nil:NilClass
1 error occurred:
An error occurred while Rails/ActiveRecordOverride cop was inspecting /crimethinc/website/app/models/advanced_search.rb:8:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.67.2 (using Parser 2.6.2.1, running on ruby 2.6.2 x86_64-darwin18)

@kyletolle
Copy link

kyletolle commented Apr 11, 2019

We've also run into this error.

Here's a simplified version of what can reproduce it:

# app/models/some_model.rb
class SomeModel < ApplicationRecord
  alias a_method another_method

  def destroy
    # Some code here.
  end
end

The presence of the alias is enough to cause the failure. Interestingly, this only happens if the file is in the app/models folder. If the file is at the root level of the project, this doesn't happen.

Here's the output:

$ rubocop -a -d app/models/some_model.rb
For <removed>: configuration from <removed>/.rubocop.yml
configuration from <removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.0.0/config/default.yml
configuration from <removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-performance-1.0.0/config/default.yml
Default configuration from <removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/config/default.yml
Inspecting 1 file
Scanning <removed>/app/models/some_model.rb
An error occurred while Rails/ActiveRecordOverride cop was inspecting <removed>/app/models/some_model.rb:6:2.
undefined method `const_name' for nil:NilClass
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/rails/active_record_override.rb:42:in `on_def'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `each'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:34:in `block (2 levels) in <class:Commissioner>'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `block in on_begin'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `each'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:50:in `on_begin'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:92:in `on_class'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:35:in `block (2 levels) in <class:Commissioner>'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/ast/traversal.rb:13:in `walk'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/commissioner.rb:46:in `investigate'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:116:in `investigate'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:104:in `offenses'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cop/team.rb:44:in `inspect_file'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:273:in `inspect_file'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:220:in `block in do_inspection_loop'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:252:in `block in iterate_until_no_changes'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `loop'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:245:in `iterate_until_no_changes'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:216:in `do_inspection_loop'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:119:in `block in file_offenses'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:137:in `file_offense_cache'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:117:in `file_offenses'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:105:in `process_file'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:82:in `block in each_inspected_file'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `reduce'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:81:in `each_inspected_file'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:73:in `inspect_files'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/runner.rb:39:in `run'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:174:in `execute_runner'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:75:in `execute_runners'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/lib/rubocop/cli.rb:47:in `run'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/exe/rubocop:25:in `block in <top (required)>'
<removed>/.rbenv/versions/2.6.2/lib/ruby/2.6.0/benchmark.rb:308:in `realtime'
<removed>/.rbenv/versions/2.6.2/lib/ruby/gems/2.6.0/gems/rubocop-0.67.2/exe/rubocop:24:in `<top (required)>'
<removed>/.rbenv/versions/2.6.2/bin/rubocop:23:in `load'
<removed>/.rbenv/versions/2.6.2/bin/rubocop:23:in `<main>'
.

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/ActiveRecordOverride cop was inspecting <removed>/app/models/some_model.rb:6:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.67.2 (using Parser 2.6.2.1, running on ruby 2.6.2 x86_64-darwin18)

diachini pushed a commit to diachini/rubocop that referenced this issue Apr 12, 2019
Fixes rubocop#6888.

This PR fixes the following error for `Rails/ActiveRecordOverride`
when there is no `parent_class` to match against.

```ruby
% cat app/models/user.rb
class User
  def initialize; end

  def create; end
end
```

```console
% rubocop app/models/user.rb --only Rails/ActiveRecordOverride -d
For /Users/dannyiachini/github/jpw/rubocop_ex: configuration from /Users/dannyiachini/github/jpw/rubocop_ex/.rubocop.yml
Default configuration from /Users/dannyiachini/.gem/ruby/2.5.3/gems/rubocop-0.67.2/config/default.yml
Inspecting 1 file
Scanning /Users/dannyiachini/github/jpw/rubocop_ex/app/models/user.rb
An error occurred while Rails/ActiveRecordOverride cop was inspecting /Users/dannyiachini/github/jpw/rubocop_ex/app/models/user.rb:6:2.
undefined method `const_name' for nil:NilClass
/Users/dannyiachini/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/rails/active_record_override.rb:42:in `on_def'

(snip)

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/ActiveRecordOverride cop was inspecting /Users/dannyiachini/github/jpw/rubocop_ex/app/models/user.rb:6:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.67.2 (using Parser 2.6.2.0, running on ruby 2.5.3 x86_64-darwin17)
```
@olegantonyan
Copy link

Yet another case when this happens

class Test
  def save
  end

  private
end

in app/models directory

@bosunolanrewaju
Copy link

bosunolanrewaju commented Apr 12, 2019

The error was introduced in v0.67.2. Had to downgrade to v0.65.0 for now

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 13, 2019

You could have also just disabled the problematic check. I guess we should suggest this workaround in the error message or something like this.

bbatsov pushed a commit that referenced this issue Apr 18, 2019
Fixes #6888.

This PR fixes the following error for `Rails/ActiveRecordOverride`
when there is no `parent_class` to match against.

```ruby
% cat app/models/user.rb
class User
  def initialize; end

  def create; end
end
```

```console
% rubocop app/models/user.rb --only Rails/ActiveRecordOverride -d
For /Users/dannyiachini/github/jpw/rubocop_ex: configuration from /Users/dannyiachini/github/jpw/rubocop_ex/.rubocop.yml
Default configuration from /Users/dannyiachini/.gem/ruby/2.5.3/gems/rubocop-0.67.2/config/default.yml
Inspecting 1 file
Scanning /Users/dannyiachini/github/jpw/rubocop_ex/app/models/user.rb
An error occurred while Rails/ActiveRecordOverride cop was inspecting /Users/dannyiachini/github/jpw/rubocop_ex/app/models/user.rb:6:2.
undefined method `const_name' for nil:NilClass
/Users/dannyiachini/.gem/ruby/2.5.3/gems/rubocop-0.67.2/lib/rubocop/cop/rails/active_record_override.rb:42:in `on_def'

(snip)

1 file inspected, no offenses detected

1 error occurred:
An error occurred while Rails/ActiveRecordOverride cop was inspecting /Users/dannyiachini/github/jpw/rubocop_ex/app/models/user.rb:6:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop-hq/rubocop/issues

Mention the following information in the issue report:
0.67.2 (using Parser 2.6.2.0, running on ruby 2.5.3 x86_64-darwin17)
```
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 a pull request may close this issue.

7 participants