class RuboCop::Cop::Cask::StanzaOrder
This cop checks that a cask's stanzas are ordered correctly. See github.com/Homebrew/homebrew-cask/blob/master/CONTRIBUTING.md#stanza-order for more info.
Constants
- MESSAGE
Attributes
cask_block[R]
Public Instance Methods
autocorrect(stanza)
click to toggle source
# File lib/rubocop/cop/cask/stanza_order.rb, line 20 def autocorrect(stanza) lambda do |corrector| correct_stanza_index = toplevel_stanzas.index(stanza) correct_stanza = sorted_toplevel_stanzas[correct_stanza_index] corrector.replace(stanza.source_range_with_comments, correct_stanza.source_with_comments) end end
on_cask(cask_block)
click to toggle source
# File lib/rubocop/cop/cask/stanza_order.rb, line 15 def on_cask(cask_block) @cask_block = cask_block add_offenses end
Private Instance Methods
add_offenses()
click to toggle source
# File lib/rubocop/cop/cask/stanza_order.rb, line 35 def add_offenses offending_stanzas.each do |stanza| message = format(MESSAGE, stanza: stanza.stanza_name) add_offense(stanza, location: stanza.source_range_with_comments, message: message) end end
offending_stanzas()
click to toggle source
# File lib/rubocop/cop/cask/stanza_order.rb, line 43 def offending_stanzas stanza_pairs = toplevel_stanzas.zip(sorted_toplevel_stanzas) stanza_pairs.each_with_object([]) do |stanza_pair, offending_stanzas| stanza, sorted_stanza = *stanza_pair offending_stanzas << stanza unless stanza == sorted_stanza end end