Module: RuboCop::Cop::InstallStepsHelper Private

Included in:
Cask::InstallSteps, FormulaAudit::InstallSteps
Defined in:
rubocops/shared/install_steps_helper.rb

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

Defined Under Namespace

Classes: InstallStepPath

Constant Summary collapse

ALLOWED_STEP_METHODS =

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(
  [:mkdir, :mkdir_p, :touch, :move, :mv, :move_children, :symlink, :ln_s, :ln_sf].freeze,
  T::Array[Symbol],
)
ALLOWED_STEP_ARGUMENT_NODE_TYPES =

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(
  [:array, :hash, :nil, :pair, :str, :sym].freeze,
  T::Array[Symbol],
)
STEP_BLOCK_MSG =

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(
  "Steps blocks may only contain install step DSL calls: " \
  "#{ALLOWED_STEP_METHODS.map { |method| "`#{method}`" }.join(", ")}.".freeze,
  String,
)
SIMPLE_STEP_CONVERSION_MSG =

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("Use `%<steps_block>s` for simple file preparation.", String)

Instance Method Summary collapse

Instance Method Details

#install_step_block_offense_node(block_node) ⇒ RuboCop::AST::Node?

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.

Parameters:

Returns:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'rubocops/shared/install_steps_helper.rb', line 30

def install_step_block_offense_node(block_node)
  return if block_node.nil?
  return if (body = block_node.body).nil?

  direct_nodes = body.begin_type? ? body.child_nodes : [body]
  direct_nodes.each do |node|
    return node unless node.send_type?

    send_node = T.cast(node, RuboCop::AST::SendNode)
    return node if send_node.receiver.present? || !ALLOWED_STEP_METHODS.include?(send_node.method_name)

    invalid_argument_node = send_node.each_descendant.find do |descendant|
      next false if descendant.false_type? || descendant.true_type?

      !ALLOWED_STEP_ARGUMENT_NODE_TYPES.include?(descendant.type)
    end
    return T.cast(invalid_argument_node, RuboCop::AST::Node) if invalid_argument_node
  end

  nil
end

#install_steps_block_source(block_name, step_lines, indent) ⇒ String

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.

Parameters:

Returns:



73
74
75
76
77
78
79
80
81
# File 'rubocops/shared/install_steps_helper.rb', line 73

def install_steps_block_source(block_name, step_lines, indent)
  block_indent = " " * indent
  step_indent = " " * (indent + 2)
  [
    "#{block_name} do",
    *step_lines.map { |step_line| "#{step_indent}#{step_line}" },
    "#{block_indent}end",
  ].join("\n")
end

#simple_install_step_lines(body_node, default_base:, default_source_base:, default_target_base:) ⇒ Array<String>?

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.

Parameters:

Returns:



60
61
62
63
64
65
66
67
68
69
70
# File 'rubocops/shared/install_steps_helper.rb', line 60

def simple_install_step_lines(body_node, default_base:, default_source_base:, default_target_base:)
  return if body_node.nil?

  direct_nodes = body_node.begin_type? ? body_node.child_nodes : [body_node]
  step_lines = direct_nodes.map do |node|
    simple_install_step_line(node, default_base:, default_source_base:, default_target_base:)
  end
  return if step_lines.any?(&:nil?)

  T.cast(step_lines, T::Array[String])
end