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

Avoid ternary operator in properties #902

Closed tas50 closed 2 years ago

tas50 commented 3 years ago

What category of cop is this?:

Please try to select as few as possible.

Describe the new cop:

We can avoid ternary operators that check if a value is an array before trying to make it an Array.

What it would trigger on:

property :template_helpers, [String, Array],
          description: 'Additional helper modules to include in the default site and config template',
          coerce: proc { |p| p.is_a?(Array) ? p : [p] }

What it would autocorrect to if applicable

property :template_helpers, [String, Array],
          description: 'Additional helper modules to include in the default site and config template',
          coerce: proc { |p| Array(p) }
tas50 commented 2 years ago

Can't always assume this will be safe