Class: RuboCop::Cop::Chef::RedundantCode::AptRepositoryNotifiesAptUpdate

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Includes:
RangeHelp, RuboCop::Chef::CookbookHelpers
Defined in:
lib/rubocop/cop/chef/redundant/apt_repository_notifies_apt_update.rb

Overview

There is no need to notify an apt-get update when an apt_repository is created as this is done automatically by the apt_repository resource.

Examples:


### incorrect
apt_repository 'my repo' do
  uri 'http://packages.example.com/debian'
  components %w(stable main)
  deb_src false
  notifies :run, 'execute[apt-get update]', :immediately
end

### correct
apt_repository 'my repo' do
  uri 'http://packages.example.com/debian'
  components %w(stable main)
  deb_src false
end

Constant Summary collapse

MSG =
'There is no need to notify an apt-get update when an apt_repository is created as this is done automatically by the apt_repository resource.'

Instance Method Summary collapse

Methods included from RuboCop::Chef::CookbookHelpers

#match_property_in_resource?, #match_resource_type?, #method_arg_ast_to_string, #resource_block_name_if_string

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_block(node) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/rubocop/cop/chef/redundant/apt_repository_notifies_apt_update.rb', line 48

def on_block(node)
  match_property_in_resource?(:apt_repository, 'notifies', node) do |notifies|
    return unless notifies.arguments[1] == s(:str, 'execute[apt-get update]')
    add_offense(notifies, severity: :refactor) do |corrector|
      corrector.remove(range_with_surrounding_space(range: notifies.loc.expression, side: :left))
    end
  end
end