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/Correctness/LazyEvalNodeAttributeDefaults does not detect nested attributes #958

Open
vytstank opened this issue Feb 13, 2023 · 0 comments
Labels
Status: Untriaged An issue that has yet to be triaged. Type: Bug Does not work as expected.

Comments

@vytstank
Copy link

Version:

cookstyle (7.32.1)
rubocop (1.25.1)
rubocop-ast (1.24.1)

Environment:

Ruby 3.0.3 with Gemfile.lock

Scenario:

Trying to lint/find Chef resources that use node attributes for default property values without lazy {}, as described in https://docs.chef.io/custom_resource_glossary/#lazy

Steps to Reproduce:

Add following properties to Chef resource:

cookbook_name/resources/test.rb

property :hostname, String, default: node['hostname']
property :release, String, default: node['kernel']['release']

Expected Result:

To have offenses shown for both properties.

Actual Result:

Cookstyle catches only default: node['hostname'] violation:

bundle exec cookstyle resources/test.rb

resources/test.rb:1:38: R: [Correctable] Chef/Correctness/LazyEvalNodeAttributeDefaults: When setting a node attribute as the default value for a custom resource property, wrap the node attribute in lazy {} so that its value is available when the resource executes. (https://docs.chef.io/workstation/cookstyle/chef_correctness_lazyevalnodeattributedefaults)
property :hostname, String, default: node['hostname']
                                     ^^^^^^^^^^^^^^^^
@vytstank vytstank added Status: Untriaged An issue that has yet to be triaged. Type: Bug Does not work as expected. labels Feb 13, 2023
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

1 participant