Class: RuboCop::Cop::Sevencop::RailsOrderFieldInOrderOf
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Sevencop::RailsOrderFieldInOrderOf
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/sevencop/rails_order_field_in_order_of.rb
Overview
Prefer ‘in_order_of` to MySQL `FIELD` function if possible.
Constant Summary collapse
- REGEXP_FIELD_DSTR_HEAD =
/ \A \s* field\( \s* (?<column_name>[^,]+) ,\s* \z /ix.freeze
- REGEXP_FIELD_DSTR_TAIL =
/ \A \s* \) \s* (?: \s+ (?<order>asc|desc) )? \z /ix.freeze
- REGEXP_FIELD_STR =
/ \A \s* field\( \s* (?<column_name>[^,]+) ,\s* (?<values>.+) \s* \) (?: \s+ (?<order>asc|desc) )? \s* \z /ix.freeze
- MSG =
'Prefer `in_order_of` to MySQL `FIELD` function if possible.'
- RESTRICT_ON_SEND =
%i[ order reorder ].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ void
This method returns an undefined value.
103 104 105 106 107 108 109 110 111 |
# File 'lib/rubocop/cop/sevencop/rails_order_field_in_order_of.rb', line 103 def on_send(node) return unless bad?(node) add_offense( convert_to_autocorrected_range(node) ) do |corrector| autocorrect(corrector, node) end end |