Class: RuboCop::Cop::Chef::Deprecations::UseYamlDump

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector
Defined in:
lib/rubocop/cop/chef/deprecation/use_yaml_dump.rb

Overview

Chef Infra Client 16.5 introduced performance enhancements to Ruby library loading. Due to the underlying implementation of Ruby’s ‘.to_yaml` method, it does not automatically load the `yaml` library and `YAML.dump()` should be used instead to properly load the `yaml` library.

Examples:


### incorrect
{"foo" => "bar"}.to_yaml

### correct
YAML.dump({"foo" => "bar"})

Constant Summary collapse

MSG =
"Chef Infra Client 16.5 introduced performance enhancements to Ruby library loading. Due to the underlying implementation of Ruby's `.to_yaml` method, it does not automatically load the `yaml` library and `YAML.dump()` should be used instead to properly load the `yaml` library."
RESTRICT_ON_SEND =
[:to_yaml].freeze

Instance Method Summary collapse

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



38
39
40
41
42
# File 'lib/rubocop/cop/chef/deprecation/use_yaml_dump.rb', line 38

def on_send(node)
  add_offense(node, severity: :warning) do |corrector|
    corrector.replace(node, "YAML.dump(#{node.receiver.source})")
  end
end