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

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, Forwardable
Includes:
IgnoredNode, CaskHelp
Defined in:
rubocops/cask/stanza_order.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

This cop checks that a cask's stanzas are ordered correctly, including nested within on_* blocks.

Constant Summary collapse

MESSAGE =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

"`%<stanza>s` stanza out of order"

Instance Method Summary collapse

Methods included from CaskHelp

#inner_stanzas, #on_block, #on_cask, #on_system_methods

Instance Method Details

#on_cask_stanza_block(stanza_block) ⇒ Object

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'rubocops/cask/stanza_order.rb', line 19

def on_cask_stanza_block(stanza_block)
  stanzas = stanza_block.stanzas
  ordered_stanzas = sort_stanzas(stanzas)

  return if stanzas == ordered_stanzas

  stanzas.zip(ordered_stanzas).each do |stanza_before, stanza_after|
    next if stanza_before == stanza_after

    add_offense(
      stanza_before.method_node,
      message: format(MESSAGE, stanza: stanza_before.stanza_name),
    ) do |corrector|
      next if part_of_ignored_node?(stanza_before.method_node)

      corrector.replace(
        stanza_before.source_range_with_comments,
        stanza_after.source_with_comments,
      )

      # Ignore node so that nested content is not auto-corrected and clobbered.
      ignore_node(stanza_before.method_node)
    end
  end
end

#on_new_investigationObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



45
46
47
48
49
# File 'rubocops/cask/stanza_order.rb', line 45

def on_new_investigation
  super

  ignored_nodes.clear
end