Chef/Style/SimplifyPlatformMajorVersionCheck
The Cookstyle cops department: Chef/Style
Enabled by default | Supports autocorrection | Target Chef Version |
---|---|---|
Enabled | Yes | All Versions |
When checking the major version number of a platform you can take the node[‘platform_version’] attribute and transform it to an integer to strip it down to just the major version number. This simple way of determining the major version number of a platform should be used instead of splitting the platform into multiple fields with ‘.’ as the delimiter.
Examples
incorrect
node['platform_version'].split('.').first
node['platform_version'].split('.')[0]
node['platform_version'].split('.').first.to_i
node['platform_version'].split('.')[0].to_i
correct
# check to see if we're on RHEL 7 on a RHEL 7.6 node where node['platform_version] is 7.6.1810
if node['platform_version'].to_i == 7
# some code
end
Configurable attributes
Name | Default value | Configurable values |
---|---|---|
Version Added | 5.8.0 | String |
Include | Array |