cookstyle
cookstyle copied to clipboard
Convert self.resource_name = :alert_manager to resource_name DSL
What category of cop is this?:
Please try to select as few as possible.
- [ ] Chef/Deprecations - A cop that alerts on a deprecation in the Chef Infra Client
- [ ] Chef/Correctness - A cop that alerts when incorrect coding behavior is being used
- [ ] Chef/Sharing - A cop that alerts to missing functionality necessary for sharing cookbooks with others
- [ ] Chef/Style - A cop that alerts to a style best practice
- [x] Chef/Modernize - A cop that alerts when a cookbook can be simplified or modernized with new functionality
- [ ] Chef/Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
Describe the new cop:
If we have a HWRP that includes self.resource_name = :alert_manager
we should just convert that to resource_name :alert_manager
to get folks closer to a standard custom resource.
What it would trigger on:
self.resource_name = A_SYMBOL
What it would autocorrect to if applicable
resource_name A_SYMBOL
This changes behavior on Chef 12-15, and can only be applied on Chef >= 16.
The reason for doing self.resource_name = :whatever
can only be to avoid the automatic canonical resource name and implicit provides stuff that was done in Chef 12-15 (you have to go out of your way to write this code, so presumably it was done for that reason), and autocorrecting it will go back to setting all of that up.
It may not break if this pattern has been copypasta'd around to resources where it doesn't matter, but for the resource which generated this pattern it will almost certainly break something.