Class: RuboCop::Cop::Cask::StanzaGrouping

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

Overview

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

Constant Summary collapse

MISSING_LINE_MSG =
"stanza groups should be separated by a single " \
"empty line"
EXTRA_LINE_MSG =
"stanzas within the same group should have no lines " \
"between them"

Instance Method Summary collapse

Methods included from CaskHelp

#on_block

Instance Method Details

#autocorrect(range) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'brew/Library/Homebrew/rubocops/cask/stanza_grouping.rb', line 28

def autocorrect(range)
  lambda do |corrector|
    case line_ops[range.line - 1]
    when :insert
      corrector.insert_before(range, "\n")
    when :remove
      corrector.remove(range)
    end
  end
end

#on_cask(cask_block) ⇒ Object



22
23
24
25
26
# File 'brew/Library/Homebrew/rubocops/cask/stanza_grouping.rb', line 22

def on_cask(cask_block)
  @cask_block = cask_block
  @line_ops = {}
  add_offenses
end