Class: RuboCop::Cop::Chef::RedundantCode::AptRepositoryDistributionDefault

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

Overview

There is no need to pass ‘distribution node[’codename’]‘ to an apt_repository resource 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
  distribution node['lsb']['codename']
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 pass `distribution node['lsb']['codename']` to an apt_repository resource 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



52
53
54
55
56
57
58
59
60
# File 'lib/rubocop/cop/chef/redundant/apt_repository_distribution_default.rb', line 52

def on_block(node)
  match_property_in_resource?(:apt_repository, 'distribution', node) do |dist|
    default_dist?(dist) do
      add_offense(dist, severity: :refactor) do |corrector|
        corrector.remove(range_with_surrounding_space(range: dist.loc.expression, side: :left))
      end
    end
  end
end