Sha256: dc146dadb5f90c1ebe656dc58d958d4606c075e4b852a14e990a2fd84e5ee454

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

#
# Copyright:: 2019, Chef Software, Inc.
# Author:: Tim Smith (<tsmith@chef.io>)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
module RuboCop
  module Cop
    module Chef
      # Instead of using the execute resource to to run the `apt-get update` use Chef Infra Client's built-n
      # apt_update resource which is available in Chef Infra Client 12.7 and later.
      #
      #   # bad
      #   execute 'apt-get update'
      #
      #   # good
      #   apt_update
      #
      class ExecuteAptUpdate < Cop
        MSG = 'Use the apt_update resource instead of the execute resource to run an apt-get update package cache update'.freeze

        def_node_matcher :execute_apt_update?, <<-PATTERN
          (send nil? :execute (str "apt-get update"))
        PATTERN

        def on_send(node)
          execute_apt_update?(node) do
            add_offense(node, location: :expression, message: MSG, severity: :refactor)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cookstyle-5.4.13 lib/rubocop/cop/chef/modernize/execute_apt_update.rb
cookstyle-5.3.6 lib/rubocop/cop/chef/modernize/execute_apt_update.rb