Hey folks,
The dust has barely settled on the Cookstyle 6.10 release, but there's a new release of Cookstyle ready to go. This release includes a new RuboCop engine and two new Chef Infra cops. With the addition of these new cops we now have 200 Chef Infra specific cops to help you write better cookbooks and upgrade your infrastructure to the latest Chef Infra Client releases. Just one year ago the very first Chef Infra cop was added to Cookstyle, and we're looking forward to adding even more as time goes on. As always if you have recommendations for new cops or issues with any of the existing cops please let us know at https://github.com/chef/cookstyle/issues
2 New Cops
ChefModernize/ConditionalUsingTest
The ChefModernize/ConditionalUsingTest cop detects resources that have an only_if or not_if conditional which uses test -e /some/file or test -f /some/file to determine if a file exists. Using the test command in a conditional requires shelling out and is slower and more resource intensive than using Ruby's built-in File.exist?('/some/file') helper.
Enabled by default: True
Autocorrects: Yes
Examples:
Conditional using test:
execute 'apt-get update' do
only_if 'test -f /usr/bin/apt'
end
Using File.exist instead:
execute 'apt-get update' do
only_if { ::File.exist?('/usr/bin/apt') }
end
ChefStyle/IncludeRecipeWithParentheses
The ChefStyle/IncludeRecipeWithParentheses cop detects unnecessary parentheses used with the include_recipe helper.
Enabled by default: True
Autocorrects: Yes
Examples:
Paranthesis with include_recipe:
include_recipe('my_recipe')
Bare include_recipe:
include_recipe 'my_recipe'
RuboCop 0.87.1
RuboCop has been updated to 0.87.1 which greatly expands the autocorrection capabilities of RuboCop and resolves many bugs in existing cops.
Other Improvements
- The
ChefModernize/NodeInitPackagecop has been improved to detect additional methods of testing a node for systemd support. - The
ChefCorrectness/IncorrectLibraryInjectioncop has been improved to detect additional incorrect methods of injecting library helpers.
Enjoy,
Tim