Sha256: df908d576e45348260619a361fa079aeee1a0f11971f8eae0ddd9ebfdbac6c20
Contents?: true
Size: 1.87 KB
Versions: 8
Compression:
Stored size: 1.87 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 module ChefCorrectness # When notifying an action within a resource the action should always be a symbol. In Chef Infra Client releases before 14.0 this may result in double notification. # # @example # # # bad # execute 'some commmand' do # notifies 'restart', 'service[httpd]', 'delayed' # end # # # good # execute 'some commmand' do # notifies :restart, 'service[httpd]', 'delayed' # end # class NotifiesActionNotSymbol < Cop include RuboCop::Chef::CookbookHelpers MSG = 'Resource notifcation actions should be symbols not strings.'.freeze def on_block(node) match_property_in_resource?(nil, 'notifies', node) do |notifies_property| add_offense(notifies_property, location: :expression, message: MSG, severity: :refactor) if notifies_property.node_parts[2].str_type? end end def autocorrect(node) lambda do |corrector| corrector.replace(node.first_argument.loc.expression, ":#{node.node_parts[2].value}") end end end end end end end
Version data entries
8 entries across 8 versions & 1 rubygems