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.

[:mkdir, :mkdir_p, :touch, :move, :mv, :move_children, :move_contents, :copy, :remove, :inreplace, :symlink,
:ln_s, :ln_sf].freeze
[:link_dir, :link_children].freeze
CONFIG_WRITE_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.

[:write].freeze
SERVICE_DATA_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.

[:init_data_dir].freeze
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.

[:compile_gsettings_schemas, :gio_querymodules, :gdk_pixbuf_query_loaders, :gtk_update_icon_cache,
:update_mime_database, :update_desktop_database].freeze
KEYCHAIN_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.

[:delete_keychain_certificate].freeze
PERMISSION_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.

[:set_permissions, :set_ownership].freeze
STEP_SCOPE_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.

[:if_path_exists, :unless_path_exists, :on_macos, :on_linux].freeze
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, *LINK_STEP_METHODS, *CONFIG_WRITE_STEP_METHODS, *SERVICE_DATA_STEP_METHODS,
   *REBUILD_ACTION_STEP_METHODS, *STEP_SCOPE_METHODS].freeze,
  T::Array[Symbol],
)
CASK_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, *CONFIG_WRITE_STEP_METHODS, *KEYCHAIN_STEP_METHODS,
   *PERMISSION_STEP_METHODS, *STEP_SCOPE_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.

dstr covers heredocs such as write content; interpolation is limited to known template values below.

[:array, :dstr, :hash, :nil, :pair, :regexp, :regopt, :str, :sym].freeze
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.

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

#append_install_step_lines(corrector, block_node, step_lines) ⇒ 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:



148
149
150
151
152
153
154
155
# File 'rubocops/shared/install_steps_helper.rb', line 148

def append_install_step_lines(corrector, block_node, step_lines)
  block_indent = block_node.source_range.column
  step_source = indented_install_step_lines(step_lines, block_indent + 2).join("\n")
  corrector.insert_before(
    block_node.loc.end,
    "#{step_source.delete_prefix(" " * block_indent)}\n#{" " * block_indent}",
  )
end

#direct_install_step_nodes(body_node) ⇒ Array<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:



158
159
160
161
162
# File 'rubocops/shared/install_steps_helper.rb', line 158

def direct_install_step_nodes(body_node)
  return [] if body_node.nil?

  body_node.begin_type? ? body_node.child_nodes : [body_node]
end

#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:



94
95
96
97
98
99
100
101
102
103
104
105
# File 'rubocops/shared/install_steps_helper.rb', line 94

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|
    offense_node = install_step_offense_node(node, allowed_methods)
    return offense_node if offense_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:



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

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

#normalised_install_step_source(node) ⇒ 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:



165
166
167
# File 'rubocops/shared/install_steps_helper.rb', line 165

def normalised_install_step_source(node)
  node.source.lines.reject { |line| line.lstrip.start_with?("#") }.join.gsub(/\s+/, " ").strip
end

#simple_install_step_lines(body_node, default_base:, default_source_base:, default_target_base:, rebuild_actions: true, permission_actions: false) ⇒ 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:

  • body_node (RuboCop::AST::Node, nil)
  • default_base (Symbol)
  • default_source_base (Symbol)
  • default_target_base (Symbol)
  • rebuild_actions (Boolean) (defaults to: true)
  • permission_actions (Boolean) (defaults to: false)

Returns:



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

def simple_install_step_lines(body_node, default_base:, default_source_base:, default_target_base:,
                              rebuild_actions: true, permission_actions: false)
  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:,
                             permission_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:



77
78
79
80
# File 'rubocops/shared/install_steps_helper.rb', line 77

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