Class: RuboCop::Cop::Chromebrew::OrderedCompatibility
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Chromebrew::OrderedCompatibility
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chromebrew/ordered_compatibility.rb
Overview
Compatibility values should be in alphabetic order.
Constant Summary collapse
- MSG =
'Compatibility values should be in alphabetical order.'
Instance Method Summary collapse
Instance Method Details
#compatibility?(node) ⇒ Object
19 20 21 22 |
# File 'lib/rubocop/cop/chromebrew/ordered_compatibility.rb', line 19 def_node_matcher :compatibility?, <<~PATTERN (send nil? :compatibility (str $_)) PATTERN |
#on_send(node) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rubocop/cop/chromebrew/ordered_compatibility.rb', line 24 def on_send(node) # Check that we're operating on the compatibility property. value = compatibility?(node) return unless value sorted_value = value.split.sort.join(' ') return if sorted_value == value # If requested, replace the offending compatibility value with the sorted version. add_offense(node.children.last) do |corrector| corrector.replace(node.children.last, "'#{sorted_value}'") end end |