Class: RuboCop::Cop::Migration::AddIndexDuplicate

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/migration/add_index_duplicate.rb

Overview

Avoid adding duplicate indexes.

Examples:

# bad
class AddIndexToUsersNameAndEmail < ActiveRecord::Migration[7.0]
  def change
    add_index :users, %w[name index]
  end
end

class AddIndexToUsersName < ActiveRecord::Migration[7.0]
  def change
    add_index :users, :name
  end
end

Constant Summary collapse

MSG =
'Avoid adding duplicate indexes.'
RESTRICT_ON_SEND =
%i[
  add_index
  index
].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ void

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


37
38
39
40
41
# File 'lib/rubocop/cop/migration/add_index_duplicate.rb', line 37

def on_send(node)
  return unless bad?(node)

  add_offense(node)
end