Cookstyle 5.21 released with 4 new Chef cops!

Hey folks,

Cookstyle 5.21 is now available on Rubygems. This release includes 4 new Chef cops as well as a large number of improvements to existing cops.

4 New Cops


The ChefStyle/UnnecessaryOSCheck cop checks cookbooks that use node['os'] to check the operating system of a node, when they could instead use the platform_family?() helper. All values of os from Ohai match one-to-one with platform_family values, except for linux which has no single equivalent plaform_family.


The ChefModernize/SimplifyAptPpaSetup cop detects apt_repository resources that setup Ubuntu PPAs by using their full URL. For example, can be simplified to just ppa:webupd8team/atom.


The ChefRedundantCode/StringPropertyWithNilDefault cop detects String type resource properties that set their default value to nil. All String type properties default to nil so this does not need to be set.


The ChefRedundantCode/PropertySplatRegex cop detects String type resource properties that validate their input with a regex of /.*/. This regex will match on any String value and is not necessary.

Other fixes and changes

  • ChefDeprecations/IncludingYumDNFCompatRecipe will now remove any inline conditionals around the include_recipe statement during autocorrection so that it does not leave behind invalid Ruby.
  • ChefDeprecations/WindowsTaskChangeAction will no longer fail when the action value is not a String type value.
  • ChefSharing/InvalidLicenseString will not autocorrect apache v2 to Apache-2.0.
  • Layout/EndAlignment and Layout/DefEndAlignment now have autocorrection enabled to eliminate the need for manually fixing indentation in cookbooks.
  • ChefStyle/UsePlatformHelpers now detects and autocorrects node['platform'].eql?() usage.
  • Style/ModuleFunction cop has been disabled because this caused library helpers to fail to load.
  • All metadata cops now properly autocorrect legacy metadata that included HEREDOCs.
  • The TargetRubyVersion is now set to 2.3 to match the version of Ruby that shipped in Chef Infra Client 12. This config value is used to enable/disable cops and autocorrection that may break Ruby code in these older Chef Infra Client releases. If you are on a later release of Chef Infra Client, you can set this value to Ruby 2.6 to enable additional cops and autocorrection.