Cookstyle 6.15 released with 8 new Ruby cops!

Hey Everyone,

This week's Cookstyle release is out with an updated RuboCop engine and new cops for the Ruby side of your cookbook work.

RuboCop 0.89.1

RuboCop has been updated to 0.89.1 which offers significant performance and autocorrection improvements to many Ruby cops that Cookstyle utilizes.

New Ruby Cops Enabled

We have enabled many new built-in RuboCop cops that we believe are also useful in correcting Chef Infra cookbooks:


The Lint/BinaryOperatorWithIdenticalOperands cop detects conditionals with duplicate checks. For example, b == 0 && b == 0 which can be simplified to just b == 0


The Lint/BinaryOperatorWithIdenticalOperands cop detects conditions with duplicate elsif checks that can be removed.


The Lint/BinaryOperatorWithIdenticalOperands cop detects duplicate rescue statements in code that can be removed.


The Lint/OutOfRangeRegexpRef detects the use of regex captures that are outside of the range of possible capture groups within a regex statement. For example, /(foo)bar/ =~ 'foobar' has a single capture so $2 is not a valid capture and will always return nil.


The Style/ArrayCoercion cop ensures a consistent method of coercing data types into Arrays. For example, this will autocorrect foo = "some_string"; [foo] into foo = "some_string"; Array(foo) and [*paths] into Array(paths) to make it more clear what is being done.


The Style/BisectedAttrAccessor cop will detect classes that include both an attr_reader and attr_writer and combine them into a single attr_accessor.


The Style/RedundantAssignment cop detects methods that assign a value to a variable immediately before returning the variable. This assignment is not necessary and increases memory usage. Instead just return the value directly.


The Style/SingleArgumentDig cop detects code that uses .dig to fetch a value from a Hash just one level deep. For example, this cop will autocorrect { key: 'value' }.dig(:key) to just { key: 'value' }[:key]