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

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

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



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

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: message) do |corrector|
          corrector.replace(item, corrected_item)
        end
      end
    end
  end
end