Skip to content

Commit

Permalink
Merge pull request #303 from chef/fix_platform_bug
Browse files Browse the repository at this point in the history
Fix autocorrection of multiple platform helpers in a recipe
  • Loading branch information
tas50 authored Oct 2, 2019
2 parents 5c46f91 + 0ac9f3e commit 8167694
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/rubocop/cop/chef/style/use_platform_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ class UsePlatformHelpers < Cop
PATTERN

def on_send(node)
platform_check?(node) do |type, plat|
# set these so we can use them in the auto_correct method
@type = type
@plat = plat

platform_check?(node) do
add_offense(node, location: :expression, message: MSG, severity: :refactor)
end
end

def autocorrect(node)
lambda do |corrector|
corrector.replace(node.loc.expression, "#{@type.value}?('#{@plat.value}')")
platform_check?(node) do |type, plat|
corrector.replace(node.loc.expression, "#{type.value}?('#{plat.value}')")
end
end
end
end
Expand Down

0 comments on commit 8167694

Please sign in to comment.