Skip to main content

Chef/Style/UnnecessaryOSCheck

Cookstyle cops page

The Cookstyle cops department: Chef/Style

Enabled by defaultSupports autocorrectionTarget Chef Version
EnabledYesAll Versions

Use the platform_family?() helpers instead of node[‘os] == ‘foo’ for platform_families that match one-to-one with OS values. These helpers are easier to read and can accept multiple platform arguments, which greatly simplifies complex platform logic. All values of os from Ohai match one-to-one with platform_family values except for linux, which has no single equivalent platform_family.

Examples

incorrect

node['os'] == 'darwin'
node['os'] == 'windows'
node['os'].eql?('aix')
%w(netbsd openbsd freebsd).include?(node['os'])

correct

platform_family?('mac_os_x')
platform_family?('windows')
platform_family?('aix')
platform_family?('netbsd', 'openbsd', 'freebsd)

Configurable attributes

NameDefault valueConfigurable values
Version Added5.21.0String
Include
    Array

    Thank you for your feedback!

    ×











    Search Results