Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LandonThomas opened this issue Jan 30, 2023 · 1 comment
Labels
Status: Untriaged An issue that has yet to be triaged. Type: Bug Does not work as expected.

Comments

@LandonThomas
Copy link

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: #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 LandonThomas added Status: Untriaged An issue that has yet to be triaged. Type: Bug Does not work as expected. labels Jan 30, 2023
@minsis
Copy link

minsis commented Apr 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Untriaged An issue that has yet to be triaged. Type: Bug Does not work as expected.
Projects
None yet
Development

No branches or pull requests

2 participants