Class: RuboCop::Cop::Rails::RedundantForeignKey
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::RedundantForeignKey
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp
- Defined in:
- lib/rubocop/cop/rails/redundant_foreign_key.rb
Overview
Detects cases where the ‘:foreign_key` option on associations is redundant.
Constant Summary collapse
- MSG =
'Specifying the default value for `foreign_key` is redundant.'
- RESTRICT_ON_SEND =
%i[belongs_to has_one has_many has_and_belongs_to_many].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rubocop/cop/rails/redundant_foreign_key.rb', line 40 def on_send(node) association_with_foreign_key(node) do |type, name, , foreign_key_pair, foreign_key| if redundant?(node, type, name, , foreign_key) add_offense(foreign_key_pair) do |corrector| range = range_with_surrounding_space(foreign_key_pair.source_range, side: :left) range = range_with_surrounding_comma(range, :left) corrector.remove(range) end end end end |