Class: RuboCop::Cop::Rails::HasAndBelongsToMany

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/rails/has_and_belongs_to_many.rb

Overview

Checks for the use of the has_and_belongs_to_many macro.

Examples:

# bad
# has_and_belongs_to_many :ingredients

# good
# has_many :ingredients, through: :recipe_ingredients

Constant Summary collapse

MSG =
'Prefer `has_many :through` to `has_and_belongs_to_many`.'
RESTRICT_ON_SEND =
%i[has_and_belongs_to_many].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



18
19
20
21
22
# File 'lib/rubocop/cop/rails/has_and_belongs_to_many.rb', line 18

def on_send(node)
  return unless node.command?(:has_and_belongs_to_many)

  add_offense(node.loc.selector)
end