Sha256: 6ece18b0a50c4712b92411f0df4986cb0567d84d26c3d24c3c5f909efe23e4fc

Contents?: true

Size: 1.99 KB

Versions: 11

Compression:

Stored size: 1.99 KB

Contents

# frozen_string_literal: true
#
# Copyright:: Copyright 2019, Chef Software Inc.
#
# 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 Correctness
        # Normal attributes are discouraged since their semantics differ importantly from the
        # default and override levels. Their values persist in the node object even after
        # all code referencing them has been deleted, unlike default and override.
        #
        # Code should be updated to use default or override levels, but this will change
        # attribute merging behavior so needs to be validated manually and force_default or
        # force_override levels may need to be used in recipe code.
        #
        # @example
        #
        #   # bad
        #   node.normal['foo'] = true
        #
        #   # good
        #   node.default['foo'] = true
        #   node.override['foo'] = true
        #   node.force_default['foo'] = true
        #   node.force_override['foo'] = true
        #
        class NodeNormal < Base
          MSG = 'Do not use node.normal. Replace with default/override/force_default/force_override attribute levels.'
          RESTRICT_ON_SEND = [:normal].freeze

          def_node_matcher :node_normal?, <<-PATTERN
            (send (send _ :node) :normal)
          PATTERN

          def on_send(node)
            node_normal?(node) do
              add_offense(node, message: MSG, severity: :refactor)
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cookstyle-7.7.2 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.6.1 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.5.3 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.5.2 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.5.1 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.4.0 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.3.11 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.3.10 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.2.1 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.1.2 lib/rubocop/cop/chef/correctness/node_normal.rb
cookstyle-7.0.0 lib/rubocop/cop/chef/correctness/node_normal.rb