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

Name Default value Configurable values
Version Added 5.6.0 String
Exclude
  • **/metadata.rb
  • **/libraries/*
  • **/Berksfile
Array

Was this page helpful?

×








Search Results