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
Comments
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 Create a PORO class with a 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 version0.67.2 (using Parser 2.6.2.1, running on ruby 2.5.3 x86_64-darwin18) |
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 Error:An error occurred while Rails/ActiveRecordOverride cop was inspecting app/models/transaction.rb:2:2.
undefined method `const_name' for nil:NilClass |
Same problem for us too. https://travis-ci.org/crimethinc/website/builds/518080309 File in question: https://github.com/crimethinc/website/blob/master/app/models/advanced_search.rb
|
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 Here's the output:
|
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) ```
Yet another case when this happens class Test
def save
end
private
end in |
The error was introduced in |
You could have also just disabled the problematic check. I guess we should suggest this workaround in the error message or something like this. |
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) ```
Expected behavior
Works without error.
Actual behavior
When run rubocop in this model:
Throw this error:
Steps to reproduce the problem
Just running rubocop in
app/models
folder of my Rails project.RuboCop version
The text was updated successfully, but these errors were encountered: