Skip to content

Rails/HasManyOrHasOneDependent false-positive when using Prism #1552

@owst

Description

@owst
class Thing < ApplicationRecord
  has_many :other_thing, through: :yet_another_thing
end

triggers a Rails/HasManyOrHasOneDependent, despite having a :through kwarg when using ParserEngine: parser_prism


Steps to reproduce the problem

Using parser_prism parse the above example file.

Expected behavior

No offense due to :through kwarg:

      # It doesn't register an offense if `:through` or `dependent: nil`
      # is specified, or if the model is read-only.

Actual behavior

False positive offense.

The node in question is

=> s(:send, nil, :has_many,
  s(:sym, :other_thing),
  s(:kwargs,
    s(:pair,
      s(:sym, :through),
      s(:sym, :yet_another_thing))))

RuboCop version

$ [rubocop -V
1.79.2 (using Parser 3.3.7.4, Prism 1.5.1, rubocop-ast 1.46.0, analyzing as Ruby 3.4, running on ruby 3.4.7) [arm64-darwin24]
  - rubocop-rails 2.33.4
  - rubocop-factory_bot 2.26.1
  - rubocop-performance 1.19.1
  - rubocop-rake 0.6.0
  - rubocop-rspec 3.4.0
  - rubocop-sorbet 0.8.7
  - rubocop-thread_safety 0.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions