Class: RuboCop::Cop::Migration::CreateTableForce

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp
Defined in:
lib/rubocop/cop/migration/create_table_force.rb

Overview

Create tables without ‘force: true` option.

The ‘force: true` option can drop an existing table. If you indend to drop an existing table, explicitly call `drop_table` first.

Examples:

# bad
class CreateUsers < ActiveRecord::Migration[7.0]
  def change
    create_table :users, force: true
  end
end

# good
class CreateUsers < ActiveRecord::Migration[7.0]
  def change
    create_table :users
  end
end

Constant Summary collapse

MSG =
'Create tables without `force: true` option.'
RESTRICT_ON_SEND =
i[
  create_table
].freeze

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ void

This method returns an undefined value.

Parameters:

  • node (RuboCop::AST::SendNode)


38
39
40
41
42
43
44
45
# File 'lib/rubocop/cop/migration/create_table_force.rb', line 38

def on_send(node)
  option_node = option_force_true_from_create_table(node)
  return unless option_node

  add_offense(option_node) do |corrector|
    autocorrect(corrector, option_node)
  end
end