Class: RuboCop::Cop::Chef::Modernize::LibarchiveFileResource

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, TargetChefVersion
Defined in:
lib/rubocop/cop/chef/modernize/libarchive_file.rb

Overview

Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive_file resource from the libarchive cookbook.

Examples:


### incorrect
depends 'libarchive'

libarchive_file "C:\file.zip" do
  path 'C:\expand_here'
end

### correct
archive_file "C:\file.zip" do
  path 'C:\expand_here'
end

Constant Summary collapse

MSG =
'Use the archive_file resource built into Chef Infra Client 15+ instead of the libarchive file resource from the libarchive cookbook'
RESTRICT_ON_SEND =
[:libarchive_file, :notifies, :subscribes].freeze

Instance Method Summary collapse

Methods included from TargetChefVersion

minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rubocop/cop/chef/modernize/libarchive_file.rb', line 51

def on_send(node)
  # The need for this goes away once https://github.com/rubocop-hq/rubocop/pull/8365 is pulled into Cookstyle
  if node.method?(:libarchive_file)
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(node, node.source.gsub('libarchive_file', 'archive_file'))
    end
  end

  notification_property?(node) do |val|
    next unless val.str_content&.start_with?('libarchive_file')
    add_offense(val, severity: :refactor) do |corrector|
      corrector.replace(node, node.source.gsub('libarchive_file', 'archive_file'))
    end
  end
end