Class: RuboCop::Cop::Bugcrowd::PreferTextToStringColumn

Inherits:
Cop
  • Object
show all
Includes:
Database
Defined in:
lib/rubocop/cop/bugcrowd/prefer_text_to_string_column.rb

Constant Summary collapse

MSG =
'Prefer text column to string, e.g. add_column :table, :column, :text. ' \
'See https://www.depesz.com/2010/03/02/charx-vs-varcharx-vs-varchar-vs-text/'

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rubocop/cop/bugcrowd/prefer_text_to_string_column.rb', line 24

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

  if add_column_with_string?(node)
    add_offense(node)
  elsif string_method_sent_to_var?(node)
    # blocks that have multiple expressions within them get wrapped
    # with a 'begin' type :shrug:
    parent = node.parent.begin_type? ? node.parent.parent : node.parent

    add_offense(node) if within_create_table_block?(parent)
  end
end