Class: RuboCop::Cop::Cask::SharedFilelistGlob Private

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
rubocops/cask/shared_filelist_glob.rb

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.

Instance Method Summary collapse

Instance Method Details

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

  • node (RuboCop::AST::SendNode)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'rubocops/cask/shared_filelist_glob.rb', line 11

def on_send(node)
  return if node.method_name != :zap

  node.each_descendant(:pair).each do |pair|
    symbols = pair.children.select(&:sym_type?).map(&:value)
    next unless symbols.include?(:trash)

    pair.each_descendant(:array).each do |array|
      regex = /\.sfl\d"$/
      message = "Use a glob (*) instead of a specific version (ie. sfl2) for trashing Shared File List paths"

      array.children.each do |item|
        next unless item.source.match?(regex)

        corrected_item = item.source.sub(/sfl\d"$/, "sfl*\"")

        add_offense(item,
                    message:) do |corrector|
          corrector.replace(item, corrected_item)
        end
      end
    end
  end
end