Class: RuboCop::Cop::Cask::InstallSteps Private

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
CaskHelp, InstallStepsHelper
Defined in:
rubocops/cask/install_steps.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 declarative install step usage.

Constant Summary collapse

INSTALL_STEP_PAIRS =

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.

T.let(
  {
    preflight:            :preflight_steps,
    postflight:           :postflight_steps,
    uninstall_preflight:  :uninstall_preflight_steps,
    uninstall_postflight: :uninstall_postflight_steps,
  }.freeze,
  T::Hash[Symbol, Symbol],
)

Constants included from InstallStepsHelper

InstallStepsHelper::ALLOWED_STEP_ARGUMENT_NODE_TYPES, InstallStepsHelper::ALLOWED_STEP_METHODS, InstallStepsHelper::FILE_PREPARATION_STEP_METHODS, InstallStepsHelper::REBUILD_ACTION_STEP_LINES, InstallStepsHelper::REBUILD_ACTION_STEP_METHODS, InstallStepsHelper::SIMPLE_STEP_CONVERSION_MSG, InstallStepsHelper::STEP_BLOCK_MSG

Instance Method Summary collapse

Methods included from InstallStepsHelper

#install_step_block_offense_node, #install_steps_block_source, #simple_install_step_lines, #step_block_msg

Methods included from CaskHelp

#cask_tap, #inner_stanzas, #on_block, #on_cask_stanza_block, #on_system_methods

Instance Method Details

#on_cask(cask_block) ⇒ void

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.

This method returns an undefined value.

Parameters:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'rubocops/cask/install_steps.rb', line 26

def on_cask(cask_block)
  stanzas = cask_block.stanzas
  INSTALL_STEP_PAIRS.each do |flight_block, steps_block|
    next unless (flight_stanza = stanzas.find { |stanza| stanza.stanza_name == flight_block })

    steps_stanza = stanzas.find { |stanza| stanza.stanza_name == steps_block }

    if steps_stanza
      add_offense(steps_stanza.source_range,
                  message: "`#{flight_stanza.stanza_name}` and `#{steps_block}` cannot both be used.")
    else
      audit_flight_block(flight_stanza, steps_block)
    end
  end

  stanzas.each do |stanza|
    next unless INSTALL_STEP_PAIRS.value?(stanza.stanza_name)
    next unless stanza.method_node.block_type?
    next unless (offense_node = install_step_block_offense_node(
      T.cast(stanza.method_node, RuboCop::AST::BlockNode),
      allowed_methods: FILE_PREPARATION_STEP_METHODS,
    ))

    add_offense(offense_node, message: step_block_msg(FILE_PREPARATION_STEP_METHODS))
  end
end