Class: RuboCop::Cop::Chef::Modernize::NodeInitPackage
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/modernize/node_init_package.rb
Overview
Use node to check for systemd instead of reading the contents of ‘/proc/1/comm’
Constant Summary collapse
- MSG =
"Use node['init_package'] to check for systemd instead of reading the contents of '/proc/1/comm'"
- RESTRICT_ON_SEND =
[:open, :read, :exist?, :==, :not_if, :only_if].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rubocop/cop/chef/modernize/node_init_package.rb', line 69 def on_send(node) compare_init_system?(node) do # if there's a ::File.exist?('/proc/1/comm') check first we want to match that as well node = node.parent if node.parent&.and_type? && proc_1_comm_exists?(node.parent.conditions.first) add_offense(node, severity: :refactor) do |corrector| corrector.replace(node, "node['init_package'] == 'systemd'") end end file_systemd_conditional?(node) do |conditional| add_offense(node, severity: :refactor) do |corrector| corrector.replace(conditional, "{ node['init_package'] == 'systemd' }") end end end |