class RuboCop::Cop::Style::SchemaComments

Constants

COMMON_DB_FIELDS
MSG

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/style/schema_comments.rb, line 12
def on_block(node)
  node.body.each_child_node do |table|
    # skip add_foreign_key, add_index
    if table.type == :block && table.send_node.source.start_with?("create_table")
      table.body.each_child_node do |ancestor|
        process_block_child_node(ancestor)
      end
    end
  end
end

Private Instance Methods

process_block_child_node(ancestor) click to toggle source
# File lib/rubocop/cop/style/schema_comments.rb, line 25
def process_block_child_node(ancestor)

  field_name = ancestor.children[2].source
  return if COMMON_DB_FIELDS.include? field_name

  last_child = ancestor.children[-1]
  return if last_child.type == :hash && last_child.each_key.any? {|key| key.source == "comment"}

  add_offense(ancestor, :expression)
end