Skip to main content

UnnecessaryPlatformCaseStatement

The department is: UnnecessaryPlatformCaseStatement

The full name of the cop is: Chef/Style/UnnecessaryPlatformCaseStatement

Enabled by default Supports autocorrection Target Chef Version
Enabled Yes All 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

Name Default value Configurable values
Version Added 5.16.0 String
Include
Array

Was this page helpful?

×









Search Results