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

FILE_PREPARATION_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],
)
REBUILD_ACTION_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(
  [:compile_gsettings_schemas, :gio_querymodules, :gdk_pixbuf_query_loaders, :gtk_update_icon_cache,
   :update_mime_database, :update_desktop_database].freeze,
  T::Array[Symbol],
)
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(
  [*FILE_PREPARATION_STEP_METHODS, *REBUILD_ACTION_STEP_METHODS].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)
REBUILD_ACTION_STEP_LINES =

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(
  T.let([
    [
      "system Formula[\"glib\"].opt_bin/\"glib-compile-schemas\", " \
      "HOMEBREW_PREFIX/\"share/glib-2.0/schemas\"",
      "compile_gsettings_schemas",
    ],
    [
      "system Formula[\"glib\"].opt_bin/\"gio-querymodules\", " \
      "HOMEBREW_PREFIX/\"lib/gio/modules\"",
      "gio_querymodules",
    ],
    [
      "system Formula[\"gdk-pixbuf\"].opt_bin/\"gdk-pixbuf-query-loaders\", " \
      "\"--update-cache\"",
      "gdk_pixbuf_query_loaders",
    ],
    [
      "system Formula[\"gtk+3\"].opt_bin/\"gtk3-update-icon-cache\", " \
      "\"-q\", \"-t\", \"-f\", HOMEBREW_PREFIX/\"share/icons/hicolor\"",
      "gtk_update_icon_cache",
    ],
    [
      "system Formula[\"shared-mime-info\"].opt_bin/\"update-mime-database\", " \
      "HOMEBREW_PREFIX/\"share/mime\"",
      "update_mime_database",
    ],
    [
      "system Formula[\"desktop-file-utils\"].opt_bin/\"update-desktop-database\", " \
      "HOMEBREW_PREFIX/\"share/applications\"",
      "update_desktop_database",
    ],
  ], T::Array[[String, String]]).to_h.freeze,
  T::Hash[String, String],
)

Instance Method Summary collapse

Instance Method Details

#install_step_block_offense_node(block_node, allowed_methods: ALLOWED_STEP_METHODS) ⇒ 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:



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'rubocops/shared/install_steps_helper.rb', line 85

def install_step_block_offense_node(block_node, allowed_methods: ALLOWED_STEP_METHODS)
  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_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:



130
131
132
133
134
135
136
137
138
# File 'rubocops/shared/install_steps_helper.rb', line 130

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:, rebuild_actions: true) ⇒ 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:



116
117
118
119
120
121
122
123
124
125
126
127
# File 'rubocops/shared/install_steps_helper.rb', line 116

def simple_install_step_lines(body_node, default_base:, default_source_base:, default_target_base:,
                              rebuild_actions: true)
  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:, rebuild_actions:)
  end
  return if step_lines.any?(&:nil?)

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

#step_block_msg(allowed_methods) ⇒ 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:



69
70
71
72
# File 'rubocops/shared/install_steps_helper.rb', line 69

def step_block_msg(allowed_methods)
  "Steps blocks may only contain install step DSL calls: " \
    "#{allowed_methods.map { |method| "`#{method}`" }.join(", ")}."
end