Class: RuboCop::Cop::Chef::Modernize::UseChefLanguageSystemdHelper

Inherits:
Base
  • Object
show all
Extended by:
AutoCorrector, TargetChefVersion
Defined in:
lib/rubocop/cop/chef/modernize/use_chef_language_systemd_helper.rb

Overview

Chef Infra Client 15.5 and later include a ‘systemd?` helper for checking if a Linux system uses systemd.

Examples:


### incorrect
node['init_package'] == 'systemd'

### correct
systemd?

Constant Summary collapse

MSG =
'Chef Infra Client 15.5 and later include a `systemd?` helper for checking if a Linux system uses systemd.'
RESTRICT_ON_SEND =
[:==].freeze

Instance Method Summary collapse

Methods included from TargetChefVersion

minimum_target_chef_version, required_minimum_chef_version, support_target_chef_version?

Methods inherited from Base

#target_chef_version

Instance Method Details

#on_send(node) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/rubocop/cop/chef/modernize/use_chef_language_systemd_helper.rb', line 49

def on_send(node)
  node_init_package?(node) do |_cloud_name|
    add_offense(node, severity: :refactor) do |corrector|
      corrector.replace(node, 'systemd?')
    end
  end
end