Class: RuboCop::Cop::Rails::UnusedIgnoredColumns

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

Overview

Suggests you remove a column that does not exist in the schema from ‘ignored_columns`. `ignored_columns` is necessary to drop a column from RDBMS, but you don’t need it after the migration to drop the column. You avoid forgetting to remove ‘ignored_columns` by this cop.

Examples:

# bad
class User < ApplicationRecord
  self.ignored_columns = [:already_removed_column]
end

# good
class User < ApplicationRecord
  self.ignored_columns = [:still_existing_column]
end

Constant Summary collapse

MSG =
'Remove `%<column_name>s` from `ignored_columns` because the column does not exist.'
RESTRICT_ON_SEND =
%i[ignored_columns=].freeze

Constants included from ActiveRecordHelper

ActiveRecordHelper::WHERE_METHODS

Instance Method Summary collapse

Methods included from ActiveRecordHelper

#external_dependency_checksum, #foreign_key_of, #in_where?, #inherit_active_record_base?, #polymorphic?, #resolve_relation_into_column, #schema, #table_name

Instance Method Details

#on_send(node) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/rails/unused_ignored_columns.rb', line 35

def on_send(node)
  return unless (columns = ignored_columns(node))
  return unless schema

  table = table(node)
  return unless table

  columns.children.each do |column_node|
    check_column_existence(column_node, table)
  end
end