lib/rubocop/cop/chef/style/use_platform_helpers.rb in cookstyle-5.20.0 vs lib/rubocop/cop/chef/style/use_platform_helpers.rb in cookstyle-5.21.9

- old
+ new

@@ -26,10 +26,11 @@ # node['platform'] == 'ubuntu' # node['platform_family'] == 'debian' # node['platform'] != 'ubuntu' # node['platform_family'] != 'debian' # %w(rhel suse).include?(node['platform_family']) + # node['platform'].eql?('ubuntu') # # # good # platform?('ubuntu') # !platform?('ubuntu') # platform_family?('debian') @@ -45,18 +46,26 @@ def_node_matcher :platform_include?, <<-PATTERN (send $(array ...) :include? (send (send nil? :node) :[] $(str {"platform" "platform_family"}))) PATTERN + def_node_matcher :platform_eql?, <<-PATTERN + (send (send (send nil? :node) :[] $(str {"platform" "platform_family"}) ) :eql? $str ) + PATTERN + def on_send(node) platform_equals?(node) do add_offense(node, location: :expression, message: MSG, severity: :refactor) end platform_include?(node) do add_offense(node, location: :expression, message: MSG, severity: :refactor) end + + platform_eql?(node) do + add_offense(node, location: :expression, message: MSG, severity: :refactor) + end end def autocorrect(node) lambda do |corrector| platform_equals?(node) do |type, operator, plat| @@ -66,9 +75,14 @@ end platform_include?(node) do |plats, type| platforms = plats.values.map { |x| x.str_type? ? "'#{x.value}'" : x.source } corrected_string = "#{type.value}?(#{platforms.join(', ')})" + corrector.replace(node.loc.expression, corrected_string) + end + + platform_eql?(node) do |type, plat| + corrected_string = "#{type.value}?('#{plat.value}')" corrector.replace(node.loc.expression, corrected_string) end end end end