class RuboCop::Cop::Chef::RedundantCode::MultiplePlatformChecks

You can pass multiple values to the platform? and platform_family? helpers instead of calling the helpers multiple times.

@example

#### incorrect
platform?('redhat') || platform?('ubuntu')
platform_family?('debian') || platform_family?('rhel')

#### correct
platform?('redhat', 'ubuntu')
platform_family?('debian', 'rhel')

Constants

MSG

Public Instance Methods

on_or(node) click to toggle source
# File lib/rubocop/cop/chef/redundant/multiple_platform_checks.rb, line 43
def on_or(node)
  or_platform_helpers?(node) do |helpers, plats|
    # if the helper types were the same it's an offense, but platform_family?('rhel') || platform?('ubuntu') is legit
    return unless helpers.uniq.size == 1

    add_offense(node, message: MSG, severity: :refactor) do |corrector|
      new_string = "#{helpers.first}(#{plats.map(&:source).join(', ')})"
      corrector.replace(node, new_string)
    end
  end
end