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

Support for `depends` with missing comma in metadata instead of `Lint/ImplicitStringConcatenation` #878

Closed collinmcneese closed 3 years ago

collinmcneese commented 3 years ago

What category of cop is this?:

Please try to select as few as possible.

Describe the new cop:

When running cookstyle against a local cookbook repository that has incorrectly-formatted depends lines which are missing a comma, Cookstyle will report the failure as Lint/ImplicitStringConcatenation. Suggestion for new feature is that we detect Lint/ImplicitStringConcatenation for depends lines in metadata.rb and suggest how it is supposed to be represented and auto-correct.

What it would trigger on:

name 'some_cookbook_210805'
maintainer 'My Name'
maintainer_email 'my@email.address'
license 'Apache-2.0'
description 'Installs/Configures some_cookbook_210805'
version '0.1.0'
chef_version '>= 15.0'

depends 'some_awesome_cookbook' '= 4.5.5'
depends 'some_other_cool_cookbook' '< 8.0'
# Cookstyle report
$ cookstyle
Inspecting 4 files
.W..

Offenses:

metadata.rb:9:9: W: Lint/ImplicitStringConcatenation: Combine 'some_awesome_cookbook' and '=4.5.5' into a single string literal, rather than using implicit string concatenation. Or, if they were intended to be separate method arguments, separate them with a comma.
depends 'some_awesome_cookbook' '= 4.5.5'
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
metadata.rb:10:9: W: Lint/ImplicitStringConcatenation: Combine 'some_other_cool_cookbook' and '< 8.0' into a single string literal, rather than using implicit string concatenation. Or, if they were intended to be separate method arguments, separate them with a comma.
depends 'some_other_cool_cookbook' '< 8.0'
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

4 files inspected, 2 offenses detected

What it would autocorrect to if applicable

depends 'some_awesome_cookbook', '= 4.5.5'
depends 'some_other_cool_cookbook', '< 8.0'

Can We Help You Implement This?:

I'm not sure what the best Cop section/name would be for something like this so I didn't suggest one 😁

tas50 commented 3 years ago

Added in 7.16