Class: RuboCop::Cop::Rails::PluckId
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::PluckId
- Extended by:
- AutoCorrector
- Includes:
- RangeHelp, ActiveRecordHelper
- Defined in:
- lib/rubocop/cop/rails/pluck_id.rb
Overview
Enforces the use of ‘ids` over `pluck(:id)` and `pluck(primary_key)`.
Constant Summary collapse
- MSG =
'Use `ids` instead of `%<bad_method>s`.'
- RESTRICT_ON_SEND =
%i[pluck].freeze
Constants included from ActiveRecordHelper
ActiveRecordHelper::WHERE_METHODS
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
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 Also known as: on_csend
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rubocop/cop/rails/pluck_id.rb', line 40 def on_send(node) return if !pluck_id_call?(node) || in_where?(node) range = offense_range(node) = format(MSG, bad_method: range.source) add_offense(range, message: ) do |corrector| corrector.replace(offense_range(node), 'ids') end end |