cookstyle icon indicating copy to clipboard operation
cookstyle copied to clipboard

Detect usage of node['platform_version'].to_f version comparisons

Open tas50 opened this issue 5 years ago • 1 comments

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.

tas50 avatar Dec 10 '19 20:12 tas50

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.

lemsx1 avatar Sep 29 '21 14:09 lemsx1