Skip to main content

Chef/Style/UnnecessaryPlatformCaseStatement

Cookstyle cops page

The Cookstyle cops department: Chef/Style

Enabled by defaultSupports autocorrectionTarget Chef Version
EnabledYesAll Versions

Use the platform?() and platform_family?() helpers instead of a case statement that only includes a single when statement.

Examples

incorrect

case node['platform']
when 'ubuntu'
  log "We're on Ubuntu"
  apt_update
end

case node['platform_family']
when 'rhel'
  include_recipe 'yum'
end

correct

if platform?('ubuntu')
  log "We're on Ubuntu"
  apt_update
end

include_recipe 'yum' if platform_family?('rhel')

Configurable attributes

NameDefault valueConfigurable values
Version Added5.16.0String
Include
    Array

    Thank you for your feedback!

    ×









    Search Results