Hey folks,
We have another great release of Cookstyle out today with 8 new cops, improvements to detection in existing cops, and a new way to enable or disable cops directly in your code.
8 New Chef Cops
ChefModernize/UnnecessaryMixlibShelloutRequire
The ChefModernize/UnnecessaryMixlibShelloutRequire cop detects providers or resources that include require 'mixlib/shellout. Chef Infra Client automatically includes the mixlib-shellout library so this require line can be removed.
Enabled by default: True
Autocorrects: Yes
ChefDeprecations/Cheffile
The ChefDeprecations/Cheffile cop will detect a Cheffile in cookbooks. librarian-chef uses this file to solve dependencies, but the librarian-chef project is no longer maintained. Users should handle dependency solving with Chef Infra Policyfiles or a Berkshelf Berksfile.
Enabled by default: True
Autocorrects: No
ChefEffortless/Berksfile
The ChefEffortless/Berksfile cop is an optional cop for detecting the use of Berkshelf's Berksfiles for cookbook dependency solving. This will help users identify cookbooks that still need to be migrated to Policyfiles before moving to the Effortless pattern.
Enabled by default: False
Autocorrects: No
ChefDeprecations/NodeDeepFetch
The ChefDeprecations/NodeDeepFetch cop detects the node.deep_fetch method which been deprecated in Chef-Sugar. Chef Infra Client's built-in node.read API should be used instead.
Enabled by default: True
Autocorrects: No
ChefModernize/IfProvidesDefaultAction
The ChefModernize/IfProvidesDefaultAction cop detects the usage of legacy if defined?(default_action) Chef Infra resources. The default_action method was added to chef-client in 0.10.8, so it is no longer necessary to conditionally call that method using if defined?.
Enabled by default: True
Autocorrects: Yes
ChefStyle/DefaultCopyrightComments
The ChefStyle/DefaultCopyrightComments cop detects cookbook copyright comment headers that still include the default NAME / ORGANIZATION information that chef generate cookbook creates. These headers should be updated with the names of the actual author or organization responsible for the cookbook.
Enabled by default: True
Autocorrects: No
ChefModernize/ZipfileResource
The ChefModernize/ZipfileResource cop detects the usage of the zipfile resource from the zipfile cookbook. Use the archive_file resource built into Chef Infra Client 15+ instead.
Enabled by default: True
Autocorrects: No
ChefCorrectness/ResourceWithNothingAction
The ChefCorrectness/ResourceWithNothingAction cop detects a resource or provider that defines its own :nothing action. There is no need to define a :nothing action in your resource as Chef Infra Client provides the :nothing action by default for every resource.
Enabled by default: True
Autocorrects: Yes
Cookstyle Comments in Code
You can now use cookstyle specific comments in your cookbook code to enable or disable cops instead of the standard rubocop comments. We think that it will be easier to understand the cops that you intend to control if you use cookstyle comments. You can continue to use the existing rubocop comments, if you prefer them, since both types of comments will be honored by Cookstyle.
Rubocop comment to disable a cop:
'node.normal[:foo] # rubocop: disable ChefCorrectness/Bar'
Cookstyle comment to disable a cop:
'node.normal[:foo] # cookstyle: disable ChefCorrectness/Bar'
Other fixes and changes
-
ChefStyle/UsePlatformHelpersnow detects and autocorrects the use of!=withnode['platform']andnode['platform_family']. For example,node['platform'] != 'ubuntu'will autocorrect to!platform?('ubuntu) -
ChefModernize/RespondToInMetadatanow detects and autocorrects the usage ofif respond_to?(:chef_version)inmetadata.rband also detects if statements are defined in additional ways. -
ChefDeprecations/UsesRunCommandHelpernow detects the usage of therun_command_with_systems_localehelper method.
Enjoy,
Tim