Closed
Description
Seeing two errors in the Rails/WhereMissing
inspections in my codebase.
Here are the two spots in the code where it fails:
model_1.rb:
def query
other_models
.left_outer_joins(left_outer_joins)
#----------------^ fails here
end
other_models
is a related has_many
model; left_outer_joins
is a method on the same model.
model_2.rb:
def call
initial_query
.joins(left_joins)
#-------^ fails here
end
initial_query
and left_joins
are methods on the same model.
Expected behavior
The two examples above should not cause Rails/WhereMissing
to fail.
Actual behavior
Running Rubocop results in the following output:
2 errors occurred:
An error occurred while Rails/WhereMissing cop was inspecting /.../app/models/model_1.rb:36:26.
An error occurred while Rails/WhereMissing cop was inspecting /.../app/models/model_2.rb:17:17.
No cops failed and all other inspections run properly.
Steps to reproduce the problem
- Create a minimal Rails app (
rails new app_name --minimal
) - Add
rubocop
androbocop-rails
to thegroup :development, :test
inGemfile
and runbundle install
:gem 'rubocop', require: false gem 'rubocop-rails', require: false
- Add a minimal
.rubocop.yml
as follows:require: - rubocop-rails AllCops: TargetRubyVersion: 2.7 NewCops: enable Style/Documentation: Enabled: false Metrics/CyclomaticComplexity: Enabled: false Metrics/PerceivedComplexity: Enabled: false Metrics/MethodLength: Enabled: false Layout/LineLength: Enabled: false
- Add two models:
bin/rails generate model user name:string bin/rails generate model product name:string user:references
- Auto-correct with
bundle exec rubocop -A
- lots of corrections, but no errors. - Modify the
User
model as follows:class User < ApplicationRecord has_many :products, dependent: :nullify def query products.left_outer_joins(left_outer_joins) #------------------------^ fails here end private def left_outer_joins [] end end
- Run
bundle exec rubocop
and you'll see the error:
❯ bundle exec rubocop
Inspecting 32 files
................................
32 files inspected, no offenses detected
An error occurred while Rails/WhereMissing cop was inspecting /Users/abcde/rubocop-error/app/models/user.rb:7:30.
To see the complete backtrace run rubocop -d.
1 error occurred:
An error occurred while Rails/WhereMissing cop was inspecting /Users/abcde/rubocop-error/app/models/user.rb:7:30.
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.58.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 2.7.8) +server [arm64-darwin22]```
## RuboCop version
1.58.0 (using Parser 3.2.2.4, rubocop-ast 1.30.0, running on ruby 2.7.8) +server [arm64-darwin22]
- rubocop-rails 2.22.2
Metadata
Metadata
Assignees
Labels
No labels
Activity