lib/rubocop/cop/chef/deprecation/chefdk_generators.rb in cookstyle-6.15.9 vs lib/rubocop/cop/chef/deprecation/chefdk_generators.rb in cookstyle-6.16.4
- old
+ new
@@ -36,21 +36,18 @@
# ChefCLI::Generator::TemplateHelper
# module ChefCLI
# ...
# end
#
- class ChefDKGenerators < Cop
+ class ChefDKGenerators < Base
+ extend AutoCorrector
MSG = 'When writing cookbook generators use the ChefCLI module instead of the ChefDK module which was removed in Chef Workstation 0.8 and later.'
def on_const(node)
# We want to catch calls like ChefCLI::CLI.whatever or places where classes are defined in the ChefDK module
return unless node.const_name == 'ChefDK' && (node.parent&.module_type? || node.parent&.const_type?)
- add_offense(node, location: :expression, message: MSG, severity: :warning)
- end
-
- def autocorrect(node)
- lambda do |corrector|
+ add_offense(node, message: MSG, severity: :warning) do |corrector|
corrector.replace(node.loc.expression, node.source.gsub('ChefDK', 'ChefCLI'))
end
end
end
end