Class: RuboCop::Cop::Cask::StanzaOrder

Inherits:
RuboCop::Cop show all
Extended by:
Forwardable
Includes:
CaskHelp
Defined in:
brew/Library/Homebrew/rubocops/cask/stanza_order.rb

Overview

This cop checks that a cask’s stanzas are ordered correctly. See https://github.com/Homebrew/homebrew-cask/blob/master/CONTRIBUTING.md#stanza-order for more info.

Constant Summary collapse

MESSAGE =
"`%{stanza}` stanza out of order"

Instance Method Summary collapse

Methods included from CaskHelp

#on_block

Instance Method Details

#autocorrect(stanza) ⇒ Object



22
23
24
25
26
27
28
29
# File 'brew/Library/Homebrew/rubocops/cask/stanza_order.rb', line 22

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) ⇒ Object



17
18
19
20
# File 'brew/Library/Homebrew/rubocops/cask/stanza_order.rb', line 17

def on_cask(cask_block)
  @cask_block = cask_block
  add_offenses
end