Skip to main content

UsePlatformHelpers

All Cookstyle Cops


The department is: Chef/Style

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


Enabled by defaultSupports autocorrectionTarget Chef Version
EnabledYesAll Versions

Use the platform?() and platform_family?() helpers instead of node[‘platform] == ‘foo’ and node[‘platform_family’] == ‘bar’. These helpers are easier to read and can accept multiple platform arguments, which greatly simplifies complex platform logic.

Examples

incorrect

node['platform'] == 'ubuntu'
node['platform_family'] == 'debian'
node['platform'] != 'ubuntu'
node['platform_family'] != 'debian'
%w(rhel suse).include?(node['platform_family'])
node['platform'].eql?('ubuntu')

correct

platform?('ubuntu')
!platform?('ubuntu')
platform_family?('debian')
!platform_family?('debian')
platform_family?('rhel', 'suse')

Configurable attributes

NameDefault valueConfigurable values
Version Added5.6.0String
Exclude
  • **/metadata.rb
  • **/libraries/*
  • **/Berksfile
Array

Was this page helpful?