Skip to main content

BlockGuardWithOnlyString

All Cookstyle Cops


The department is: Chef/Correctness

The full name of the cop is: Chef/Correctness/BlockGuardWithOnlyString


Enabled by defaultSupports autocorrectionTarget Chef Version
EnabledYesAll Versions

A resource guard (not_if/only_if) that is a string should not be wrapped in {}. Wrapping a guard string in {} causes it to be executed as Ruby code which will always returns true instead of a shell command that will actually run.

Examples

incorrect

template '/etc/foo' do
  mode '0644'
  source 'foo.erb'
  only_if { 'test -f /etc/foo' }
end

correct

template '/etc/foo' do
  mode '0644'
  source 'foo.erb'
  only_if 'test -f /etc/foo'
end

Configurable attributes

NameDefault valueConfigurable values
Version Added5.2.0String
Exclude
  • **/attributes/*.rb
  • **/metadata.rb
  • **/Berksfile
Array

Was this page helpful?









Search Results