Class: RuboCop::Cop::Rails::PluralizationGrammar
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::PluralizationGrammar
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/rails/pluralization_grammar.rb
Overview
Checks for correct grammar when using ActiveSupport’s core extensions to the numeric classes.
Constant Summary collapse
- SINGULAR_METHODS =
{ second: :seconds, minute: :minutes, hour: :hours, day: :days, week: :weeks, fortnight: :fortnights, month: :months, year: :years, byte: :bytes, kilobyte: :kilobytes, megabyte: :megabytes, gigabyte: :gigabytes, terabyte: :terabytes, petabyte: :petabytes, exabyte: :exabytes, zettabyte: :zettabytes }.freeze
- RESTRICT_ON_SEND =
SINGULAR_METHODS.keys + SINGULAR_METHODS.values
- PLURAL_METHODS =
SINGULAR_METHODS.invert.freeze
- MSG =
'Prefer `%<number>s.%<correct>s`.'
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rubocop/cop/rails/pluralization_grammar.rb', line 49 def on_send(node) return unless duration_method?(node.method_name) && literal_number?(node.receiver) && offense?(node) number, = *node.receiver add_offense(node, message: (number, node.method_name)) do |corrector| method_name = node.loc.selector.source corrector.replace(node.loc.selector, correct_method(method_name)) end end |