cookstyle icon indicating copy to clipboard operation
cookstyle copied to clipboard

Chef/Modernize/CronDFileOrTemplate causes RuboCop error on non-cron file resources

Open LandonThomas opened this issue 2 years ago • 1 comments

Version:

Cookstyle 7.32.1
  * RuboCop 1.25.1

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:

[ %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:

Chef/Modernize/CronDFileOrTemplate:
  Enabled: false

Cookstyle returns:

% cookstyle
Inspecting 4 files
....

4 files inspected, no offenses detected

Actual Result:

Within the example cookbook:

% 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)

LandonThomas avatar Jan 30 '23 18:01 LandonThomas

Also to add its triggering on /etc/cron.deny file as well.

minsis avatar Apr 14 '23 18:04 minsis