cookstyle
cookstyle copied to clipboard
Detect usage of node['platform_version'].to_f version comparisons
What category of cop is this?:
Please try to select as few as possible.
- [ ] ChefDeprecations - A cop that alerts on a deprecation in the Chef Infra Client
- [ ] ChefCorrectness - A cop that alerts when incorrect coding behavior is being used
- [ ] ChefSharing - A cop that alerts to missing functionality necessary for sharing cookbooks with others
- [ ] ChefStyle - A cop that alerts to a style best practice
- [ ] ChefModernize - A cop that alerts when a cookbook can be simplified or modernized with new functionality
- [ ] ChefEffortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
Describe the new cop:
When people compare version strings they have a bad time since .10 becomes .1 in a float. Example from Debian:
9.9 > 9.10 => true
What it would trigger on:
node['platform_version'].to_f OPERATOR INT
What it would autocorrect to if applicable
We need to ship a helper for version comparisons in Chef client and then point people at that instead.
Ruby 2.5 and up seem to ship with a version comparison API under Gem::Version.<=>. This should be re-written so people can compare versions properly that way.