A linting tool that helps you to write better Chef Infra cookbooks and InSpec profiles by detecting and automatically correcting style, syntax, and logic mistakes in your code.
Apache License 2.0
109
stars
54
forks
source link
Chef/Modernize/CronDFileOrTemplate causes RuboCop error on non-cron file resources #957
MacOS 11.6.4 running Chef Workstation 22.10.1013 using example cookbook code.
Scenario:
When file resources iterate through loops and interpolate strings from embedded arrays, it can trigger an error from the Chef/Modernize/CronDFileOrTemplate cop, even through crond isn't in scope.
Steps to Reproduce:
Create an example cookbook with this recipe code:
[ %w( test /etc/file1 ) ].each do |arr|
file "file_#{arr[1]}" do
path arr[1]
end
end
s = Set[]
s.add([ 'test', '/etc/file2'])
s.each do |arr|
file "file_#{arr[1]}" do
path arr[1]
end
end
{
files: [ 'test', '/etc/file3'],
}.each do |title, config|
file "file_#{title}" do
path config[1]
end
end
This is based on code I'm seeing triggering the error but I tried to simplify it as much as I could.
Expected Result:
I have code like this throughout my app stack and recently I've gotten multiple errors whereas in the past they passed. I suspect this change introduced the bug: https://github.com/chef/cookstyle/pull/941
If I add .rubocop.yml to the cookbook base directory with this content:
% cookstyle
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:2:2.
To see the complete backtrace run rubocop -d.
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:10:2.
To see the complete backtrace run rubocop -d.
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:18:2.
To see the complete backtrace run rubocop -d.
Inspecting 4 files
..An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:2:2.
To see the complete backtrace run rubocop -d.
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:10:2.
To see the complete backtrace run rubocop -d.
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:18:2.
To see the complete backtrace run rubocop -d.
..
4 files inspected, no offenses detected
3 errors occurred:
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:2:2.
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:10:2.
An error occurred while Chef/Modernize/CronDFileOrTemplate cop was inspecting /Users/user1234/chef/example_cookbook/recipes/default.rb:18:2.
Errors are usually caused by RuboCop bugs.
Please, report your problems to RuboCop's issue tracker.
https://github.com/rubocop/rubocop/issues
Mention the following information in the issue report:
1.25.1 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 3.0.3 x86_64-darwin19)
Version:
Environment:
MacOS 11.6.4 running Chef Workstation 22.10.1013 using example cookbook code.
Scenario:
When file resources iterate through loops and interpolate strings from embedded arrays, it can trigger an error from the Chef/Modernize/CronDFileOrTemplate cop, even through crond isn't in scope.
Steps to Reproduce:
Create an example cookbook with this recipe code:
This is based on code I'm seeing triggering the error but I tried to simplify it as much as I could.
Expected Result:
I have code like this throughout my app stack and recently I've gotten multiple errors whereas in the past they passed. I suspect this change introduced the bug: https://github.com/chef/cookstyle/pull/941
If I add
.rubocop.yml
to the cookbook base directory with this content:Cookstyle returns:
Actual Result:
Within the example cookbook: