Hey folks,
Cookstyle 5.13 has been released with 3 new Chef cops and a few nice improvements. With this release we now have 130 total Chef cops in Cookstyle. As always if you find something you think we should and could detect feel free to report an issue: https://github.com/chef/cookstyle/issues/new
3 New Chef Cops
ChefDeprecations/LegacyNotifySyntax
The ChefDeprecations/LegacyNotifySyntax cop detects the legacy notification syntax in resources. The newer notification method supports notifying resources that occur later in the recipe and should be used instead.
Legacy notification syntax:
notifies :restart, resources(service: 'apache')
New notification syntax:
notifies :restart, 'service[apache]'
Enabled by default: True
Autocorrects: Yes
ChefDeprecations/NodeSetWithoutLevel
The ChefDeprecations/NodeSetWithoutLevel cop detects recipes and resources that set node attributes without specifying the precedence level required by Chef Infra Client 11 and later.
Setting node attributes without a precedence level:
node['foo']['bar'] = 1
node['foo']['bar'] << 1
node['foo']['bar'] += 1
node['foo']['bar'] -= 1
Setting node attributes with a precedence level of override:
node.override['foo']['bar'] = 1
node.override['foo']['bar'] << 1
node.override['foo']['bar'] += 1
node.override['foo']['bar'] -= 1
Enabled by default: True
Autocorrects: No
ChefModernize/EmptyResourceInitializeMethod
The ChefModernize/EmptyResourceInitializeMethod cop detects empty initialize methods in resources and providers. These methods are usually left over from refactoring older HWRP-style resources into simpler custom resources and they can be removed.
Enabled by default: True
Autocorrects: Yes
Other fixes and changes
- The JSON output formatter now exposes offenses that could be auto-corrected with a new
correctablefield in the hash. - The
ChefModernize/DefaultActionFromInitializecop will no longer insert adefault_actioninto the resource if one already exists.
Enjoy,
Tim