chef / cookstyle

A linting tool that helps you to write better Chef Infra cookbooks and InSpec profiles by detecting and automatically correcting style, syntax, and logic mistakes in your code.
Apache License 2.0
107 stars 54 forks source link

Conditional use of `unified_mode true` needs to warn #936

Open lamont-granquist opened 2 years ago

lamont-granquist commented 2 years ago
unified_mode true if respond_to?(:unified_mode)

That isn't a coherent thing to ever want to do, since you get unified_mode true behavior on newer chef-client and unified_mode false behavior on older chef-client and will require careful testing on all versions, and crazy questions to me on how to write code so that it works the same both ways.

In general people need to pick one way or the other, and have backwards compatibility via unified_mode false (and suffer the deprecation warning forever reminding you that support for Chef 12 has been dropped ages ago) or else set unified_mode true and properly drop support for old Chef 12

lamont-granquist commented 2 years ago

What is okay to do is the other boolean:

unified_mode false if respond_to?(:unified_mode)

That is fine. That turns off unified_mode everywhere and you can write your resources old-style forever and opt-out of unified mode.

Individual sites can ever put this in config.rb (or kitchen.yml settings):

silence_deprecation_warnings %w{unified_mode}