I am trying to use an array in Chef for platform_family, and according to the chef docs I have the right syntax, but rubocop is kicking my butt.
Chef docs: https://docs.chef.io/dsl_recipe.html#value-for-platform-family
Any thoughts for a ruby newb?
12 tcp_ports = value_for_platform_family(
13 ['debian', 'rhel'] => [22, 443, 4172, 60443],
14 'windows' => [443, 3389, 4172, 60443]
15 )
And the rubocop error is
recipes/recipe.rb:13:3: C: Style/WordArray: Use %w or %W for an array of words.
['debian', 'rhel'] => [22, 443, 4172, 60443],
^^^^^^^^^^^^^^^^^^
When working with collections Rubocop adds:
Prefer %w to the literal array syntax when you need an array of words (non-empty strings without spaces and special characters in them). Apply this rule only to arrays with two or more elements.
# bad
STATES = ['draft', 'open', 'closed']
# good
STATES = %w[draft open closed]
Notice, this is bad from the view point in the Ruby Style Guide, but still working code.
So your example would be:
%w[debian rhel]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With