class RuboCop::Cop::Chef::Correctness::InvalidPlatformMetadata

metadata.rb `supports` methods should contain valid platforms. See [Infra Language: Platform](docs.chef.io/infra_language/checking_platforms/#platform-values) for a list of many common platform values.

@example

#### incorrect
supports 'darwin'
supports 'mswin'

#### correct
supports 'mac_os_x'
supports 'windows'

Constants

MSG
RESTRICT_ON_SEND

Public Instance Methods

corrected_platform_source(node) click to toggle source

private

# File lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb, line 78
def corrected_platform_source(node)
  val = INVALID_PLATFORMS[node.str_content.delete(',').downcase]
  return false unless val

  # if the value was previously quoted make sure to quote it again
  node.source.match?(/^('|")/) ? "'" + val + "'" : val
end
on_block(node) click to toggle source
# File lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb, line 63
def on_block(node)
  supports_array?(node) do |plats|
    plats.values.each do |plat|
      next unless INVALID_PLATFORMS[plat.str_content]
      add_offense(plat, message: MSG, severity: :refactor) do |corrector|
        correct_string = corrected_platform_source(plat)
        next unless correct_string
        corrector.replace(plat, correct_string)
      end
    end
  end
end
on_send(node) click to toggle source
# File lib/rubocop/cop/chef/correctness/invalid_platform_metadata.rb, line 52
def on_send(node)
  supports?(node) do |plat|
    next unless INVALID_PLATFORMS[plat.str_content]
    add_offense(plat, message: MSG, severity: :refactor) do |corrector|
      correct_string = corrected_platform_source(plat)
      next unless correct_string
      corrector.replace(plat, correct_string)
    end
  end
end