ChefApplicationFatal
The complete name of the cop is: Chef/Correctness/ChefApplicationFatal
ChefApplicationFatal is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions.
We use raise to force the Chef Infra Client to fail rather than using Chef::Application.fatal, as it masks the full stack trace of the failure and makes debugging harder.
Examples
Incorrect:
Chef::Application.fatal!('Something horrible happened!')
Correct:
raise "Something horrible happened!"
Configurable Attributes:

ConditionalRubyShellout
The complete name of the cop is: Chef/Correctness/ConditionalRubyShellout
ConditionalRubyShellout is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions.
We don’t use Ruby to shell out in case of only_if / not_if conditionals because any string value will get executed in your system’s shell and the return code is the result for only_if / not_if determination.
Examples
Incorrect:
cookbook_file '/logs/foo/error.log' do
source 'error.log'
only_if { system('wget https://www.bar.com/foobar.txt -O /dev/null') }
end
cookbook_file '/logs/foo/error.log' do
source 'error.log'
only_if { shell_out('wget https://www.bar.com/foobar.txt -O /dev/null').exitstatus == 0 }
end
Correct:
cookbook_file '/logs/foo/error.log' do
source 'error.log'
only_if 'wget https://www.bar.com/foobar.txt -O /dev/null'
end
Configurable Attributes:

IncorrectLibraryInjection:

The complete name of the cop is: Chef/Correctness/IncorrectLibraryInjection
IncorrectLibraryInjection is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions.
The libraries being injected should be injected into the Chef::DSL::Recipe class and not Chef::Recipe or Chef::Provider classes.
Examples
Incorrect:
::Chef::Recipe.send(:include, Filebeat::Helpers)
::Chef::Provider.send(:include, Filebeat::Helpers)
::Chef::Recipe.include Filebeat::Helpers
::Chef::Provider.include Filebeat::Helpers
Correct:
::Chef::DSL::Recipe.send(:include, Filebeat::Helpers) # covers previous Recipe & Provider classes
Configurable Attributes:

DnfPackageAllowDowngrades:
The complete name of the cop is: Chef/Correctness/DnfPackageAllowDowngrades
DnfPackageAllowDowngrades is a cookstyle cop that is enabled by Default and supports autocorrection. It is a cop that can be used in all chef versions.
The resource of dnf_package doesn’t support the allow_downgrades property.
Examples
Incorrect:
dnf_package 'nginx' do
version '1.2.3'
allow_downgrades true
end
Correct:
dnf_package 'nginx' do
version '1.2.3'
end
Configurable Attributes:

CookbookUsesNodeSave:
The complete name of the cop is: Chef/Correctness/CookbookUsesNodeSave
CookbookUsesNodeSave is a cookstyle cop that is enabled by Default and it does not support autocorrection. It is a cop that can be used in all chef versions.
Never use node.save to save partial data to the server mid-run unless it’s a requirement of the cookbook design that’s inevitable as it can result in failed runs appearing in search as well as it increases the load on the chef infra server.
Examples
Incorrect:
node.save
Configurable Attributes:

InvalidCookbookName:
The complete name of the cop is: Chef/Correctness/InvalidCookbookName
InvalidCookbookName is a cookstyle cop that is enabled by Default and it does not support autocorrection. It is a cop that can be used in all chef versions.
The Cookbook name shouldn’t contain any invalid characters like periods or commas.
Examples
Incorrect:
name 'foo.bar'
Correct:
name 'foo_bar'
Configurable Attributes:

InvalidDefaultAction:
The complete name of the cop is: Chef/Correctness/InvalidDefaultAction
InvalidDefaultAction is a cookstyle cop that is enabled by Default and it does not support autocorrection. It is a cop that can be used in all chef versions.
The default actions should be symbols/arrays of symbols.
Examples
Incorrect:
default_action 'create'
Correct:
default_action :create
Configurable Attributes:

InvalidNotificationResource
The complete name of the cop is: Chef/Correctness/InvalidNotificationResource
InvalidNotificationResource is a cookstyle cop that is enabled by Default and it does not support autocorrection. It is a cop that can be used in all chef versions.
The resource used to call notifies or subscribes should be a string.
Examples
Incorrect:
template '/etc/www/configures-apache.conf' do
notifies :restart, service['apache'], :immediately
end
template '/etc/www/configures-apache.conf' do
notifies :restart, service[apache], :immediately
end
Correct:
template '/etc/www/configures-apache.conf' do
notifies :restart, 'service[apache]', :immediately
end
Configurable Attributes:

InvalidNotificationTiming
The complete name of the cop is: Chef/Correctness/InvalidNotificationTiming
InvalidNotificationTiming is a cookstyle cop that is enabled by Default and it does not support autocorrection. It is a cop that can be used in all chef versions.
The valid notification timings possible are :immediate, :immediately, :delayed & :before
Examples
Incorrect:
template '/etc/www/configures-apache.conf' do
notifies :restart, 'service[apache]', :nope
end
Correct:
template '/etc/www/configures-apache.conf' do
notifies :restart, 'service[apache]', :immediately
end
Configurable Attributes:

Must Read Apache Server
InvalidPlatformFamilyHelper
The complete name of the cop is: Chef/Correctness/InvalidPlatformFamilyHelper
InvalidPlatformFamilyHelper is a cookstyle cop that is enabled by Default and it supports autocorrection. It is a cop that can be used in all chef versions.
Pass valid platform families to the platform_family? helper.
Examples
Incorrect:
platform_family?('redhat')
platform_family?('sles')
#### incorrect
```ruby
platform_family?('rhel')
platform_family?('suse')
Configurable Attributes:

InvalidPlatformFamilyInCase
The complete name of the cop is: Chef/Correctness/InvalidPlatformFamilyInCase
InvalidPlatformFamilyInCase is a cookstyle cop that is enabled by Default and it supports autocorrection. It is a cop that can be used in all chef versions.
The valid platform family values have to be in case statements to be used.
Examples
Incorrect:
case node['platform_family']
when 'redhat'
puts "I'm on a RHEL-like system"
end
Configurable Attributes:

InvalidPlatformHelper
The complete name of the cop is: Chef/Correctness/InvalidPlatformHelper
InvalidPlatformHelper is a cookstyle cop that is enabled by Default and it does not support autocorrection. It is a cop that can be used in all chef versions.
Only pass valid platforms to the platform? helper.
Examples
Incorrect:
platform?('darwin')
platform?('rhel')
platform?('sles')
Correct:
platform?('mac_os_x')
platform?('redhat')
platform?('suse')
Configurable Attributes:

Frequently Asked Questions
What is Progress Chef?
Progress Chef is a configuration management tool that provides a way to define infrastructure as code, i.e., a method to manage infrastructure without using manual processes. Chef uses pure Ruby, Domain Specific Language, to write system configurations.
What is Cookstyle?
Cookstyle is a linting tool that helps improve the cookbook code by automatically correcting syntax, style, and logical errors in your code.
What are Policyfiles?
Policyfiles are a way to create an immutable collection of cookbooks, their dependencies, and attributes that are defined in a single document uploaded to the Chef Infra server.
Conclusion
So, with this, we saw about the Chef/Correctness section of the Cookstyle tool. I hope the blog was informative.
See Basics of C++ with Data Structure, DBMS, Operating System by Coding Ninjas, and keep practicing on our platform Coding Ninjas Studio.
If you think you are ready for the tech giants company, check out the mock test series on code studio.
You can also refer to our Guided Path on Coding Ninjas Studio to upskill yourself in domains like Data Structures and Algorithms, Competitive Programming, Aptitude, and many more! You can also prepare for tech giants companies like Amazon, Microsoft, Uber, etc., by looking for the questions asked by them in recent interviews. If you want to prepare for placements, refer to the interview bundle. If you are nervous about your interviews, you can see interview experiences to get ideas about these companies' questions.
Nevertheless, you may consider our premium courses to give your career an edge over others!
Do upvote our blogs if you find them helpful and engaging!
Happy Learning!
