Giter Club home page Giter Club logo

cookstyle's Introduction

Chef Cookstyle - Chef Infra Cookbook and InSpec profile linting with autocorrection

Build status Gem Version

Cookstyle is a code linting tool that helps you to write better Chef Infra cookbooks and InSpec profiles by detecting and automatically correcting style, syntax, logic, and security mistakes in your code.

Cookstyle is powered by the RuboCop linting engine. RuboCop ships with over three-hundred rules, or cops, designed to detect common Ruby coding mistakes and enforce a common coding style. We've customized Cookstyle with a subset of those cops that we believe are perfectly tailored for cookbook development. We also ship 259 Chef Infra specific cops that catch common cookbook coding mistakes, cleanup portions of code that are no longer necessary, and detect deprecations that prevent cookbooks from running on the latest releases of Chef Infra Client.

For complete usage documentation along with documentation for all the included cops see https://docs.chef.io/workstation/cookstyle/

Cookstyle vs. RuboCop

How does Cookstyle differ from RuboCop?

Tailored for Cookbooks and Profiles

Cookbook and profile development differs from that of traditional Ruby software development, so we have tailored the list of built-in cops in RuboCop for cookbook development. For the most part, this means disabling cops deemed not useful for cookbook development. Occasionally, we've changed the configuration of a rule to enforce a different behavior altogether. We've also extended the base RuboCop package with a set of our own Chef Infra-specific cops. These cops are only found in Cookstyle and will help you to write more reliable and future-proof cookbooks.

See the current set of cops in Cops Documentation

Stable

RuboCop is an incredibly active project with new cops being introduced monthly. The new cops cause existing codebases to fail CI tests and force authors to constantly update their code. With Cookstyle, we update the RuboCop engine for bug and performance fixes, but we only change the set of cops that will fail tests once a year during Chef Infra's April major release. All new cops are introduced at RuboCop's "refactor" alert level, meaning they will alert to the screen as you run Cookstyle, but they won't fail a build. This stability means you are free to upgrade releases of Cookstyle without being forced to update your infrastructure code.

Cookstyle vs. Foodcritic

Cookstyle is the replacement for Foodcritic. For more information on why we decided to replace Foodcritic see our blog post Goodbye Foodcritic

Installation

Cookstyle is included in Chef Workstation. If you choose not to use the Chef Workstation package, you can still install Cookstyle manually using the instructions below.

Add this line to your application's Gemfile:

gem 'cookstyle'

And then execute:

bundle

Or install it yourself as:

gem install cookstyle

Usage

cookstyle Command

Use this tool just as you would RuboCop, but invoke the cookstyle binary instead, which patches RuboCop to load cops from the cookstyle gem. For example:

cookstyle -D --format offenses

Rake

In a Rakefile, the setup is similar, except you need to require the cookstyle library first:

require 'cookstyle'
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:cookstyle) do |task|
  task.options << '--display-cop-names'
end

From RuboCop

Run RuboCop as normal, and simply add a -r cookstyle option when running:

rubocop -r cookstyle -D --format offenses

guard-rubocop

You can use one of two methods. The simplest is to add the -r cookstyle option to the :cli option in your Guardfile:

guard :rubocop, cli: "-r cookstyle" do
  watch(%r{.+\.rb$})
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

Alternatively you could pass the path to Cookstyle's configuration by using the Cookstyle.config method:

require "cookstyle"

guard :rubocop, cli: "--config #{Cookstyle.config}" do
  watch(%r{.+\.rb$})
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

.rubocop.yml

As with RuboCop, any custom settings can still be placed in a .rubocop.yml file in the root of your project.

Testing Against Specific Chef Versions

Many of the cops included in Cookstyle will autocorrect Chef Infra cookbook code in ways that will require fairly recent releases of Chef Infra Client in order to run those cookbooks. For example the Chef/Modernize/UnnecessaryDependsChef14 cop will remove cookbook dependencies from your metadata.rb which are no longer necessary with Chef Infra Client 14+. This cop would be problematic if you ran it against your cookbooks, and had yet to upgrade your fleet of systems to Chef Infra Client 14+. For this reason you may want to configure Cookstyle to skip cops that would be destructive on older version of Chef Infra Client by setting.

Cookstyle now includes a new top-level configuration option TargetChefVersion. This new configuration option works similarly to RuboCop's TargetRubyVersion config option and allows you to specify a Chef Infra version that you want to target in your Cookstyle analysis. By setting the target version you disable incompatible cops and autocorrect from running. This allows you to gradually update your target version to allow stepped upgrades of Chef Infra Client such as 12.something -> 12.latest -> 13.latest -> 14.latest -> 15.latest.

Example .rubocop.yml config specifying a TargetChefVersion of 14.0:

AllCops:
  TargetChefVersion: 14.0

Getting Involved

We'd love to have your help in developing Cookstyle. See our Contributing Guide for more information on contributing to Chef projects. There's also a Developer Guide for Cookstyle that outlines how the configs work and how you can upgrade the RuboCop engine.

License and Copyright

Copyright 2016-2021, Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

cookstyle's People

Contributors

ashiqueps avatar chef-ci avatar chef-expeditor[bot] avatar dafyddcrosby avatar damacus avatar eladitzhakian avatar ianmadd avatar iennae avatar jakauppila avatar jamesnearn avatar jamietanna avatar jaymzh avatar karmix avatar lamont-granquist avatar martinisoft avatar mattray avatar phiggins avatar ramereth avatar rmoriz avatar robbkidd avatar skeshari12 avatar snohio avatar tas50 avatar tduffield avatar thommay avatar tpowell-progress avatar tyler-ball avatar xorima avatar yacn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cookstyle's Issues

[Enhancement] A single config file to use with vanilla rubocop

I'm using RubyMine as my IDE. There is a Rubcop plugin that looks for .rubocop.yml by default, so I just put the content of cookstyle.yml into a .rubocop.yml file. However, the rules don't seem to match up with the results of running cookstyle against the same cookbook.

$ curl https://raw.githubusercontent.com/chef/cookstyle/master/config/cookstyle.yml > .rubocop.yml
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3265  100  3265    0     0  29487      0 --:--:-- --:--:-- --:--:-- 34010
$ which rubocop; rubocop --version
/opt/chefdk/embedded/bin/rubocop
0.49.1
$ rubocop --config .rubocop.yml
Inspecting 24 files
......W..W.........C...C

[various offenses are shown here]

24 files inspected, 6 offenses detected
$ which cookstyle; cookstyle --version
/opt/chefdk/bin/cookstyle
Cookstyle 2.1.0
  * RuboCop 0.49.1
$ cookstyle
Inspecting 24 files
........................

24 files inspected, no offenses detected

I'm not super familiar with how rubocop works, but I imagine there would be a way to get all the active rules into cookstyle.yml? I don't really understand the relationship between all of the files in config/.

Edit: It turns out that looking at source code makes sense. I see this now in config/default.yml:

inherit_from:
  - upstream.yml
  - disable_all.yml
  - cookstyle_base.yml
  - cookstyle.yml

Still, it would be nice to a single config have a file that vanilla rubocop can use without all of the inheritance that yields the same result as running cookstyle

Edit 2: Okay, even with all of the files in config/ I run into this error:

$ rubocop --config default.yml
Error: The `Style/MethodCallParentheses` cop has been renamed to `Style/MethodCallWithoutArgsParentheses`.
(obsolete configuration found in /Users/erichanko/chef-repo/Cookbooks/macos-cookbook/cookstyle_base.yml, please update it)
The `Style/DeprecatedHashMethods` cop has been renamed to `Style/PreferredHashMethods`.
(obsolete configuration found in /Users/erichanko/chef-repo/Cookbooks/macos-cookbook/cookstyle_base.yml, please update it)

Consider disabling Style/SymbolProc

Greetings!

A problematic use case we have run across is if we want to lazily include a resource propery in another property like so:

property :setgid, String, default: lazy { |resource| resource.run_group }

This works as it's acting upon another property of the resource, however cookstyle will flag this as a violation and provide this fix:

property :setgid, String, default: lazy(&:run_group)

While this is a clever ruby trick, because lazy is not implicitly passing in resource (just in this context it is) Chef immediately crashes with a stacktrace in the log output with >>>> Caused by ArgumentError: no receiver given

I'd suggest turning off this cop not just for this use case, but also readability. Symbol to proc shortcuts are cute, but I think it's a more advanced ruby concept most folks won't be able to grok.

Detect if someone specifies env vars in cron_d that have their own property

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

We have properties for many of the env vars. Users should use those instead of using the env vars via the environment property.

What it would trigger on:

Any value in the environment hash that has its own property like random_delay.

What it would autocorrect to if applicable

We could just extra the values from the hash and use the properties instead.

See https://github.com/chef/chef/blob/master/lib/chef/resource/cron_d.rb#L160

Remove any attributes in the metadata.rb file

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

We no longer support documenting attributes in the metadata.rb file. We should remove these if we find them

What it would trigger on:

attribute 'accounts', display_name: 'Accounts Hash',
                      description: 'Hash of Accounts attributes',
                      type: 'hash'

What it would autocorrect to if applicable

Just delete it

Possible Issue with cookstyle and http file inherited config files

I am not sure if this is an issue with cookstyle or rubocop core. I have only seen it happen when using cookstyle however. It seems to happens when it can't download a file randomly from an http endpoint. In our case it shows much more when we run it in jenkins as it does a clean before build so that file always gets deleted. I have not had this issue with rubocop so I am not sure if anything in cookstyle could cause this.

Running shell script
+ cookstyle .
No such file or directory @ rb_sysopen - /jenkins/workspace/cookbook/.rubocop-https---raw-githubusercontent-com-rubocop-rules-chef-master-rubocop-yml
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:143:in `read'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:143:in `load_yaml_configuration'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:35:in `load_file'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:81:in `block in base_configs'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:68:in `map'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:68:in `base_configs'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader_resolver.rb:22:in `resolve_inheritance'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:38:in `load_file'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_loader.rb:97:in `configuration_from_file'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/config_store.rb:41:in `for'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/cli.rb:88:in `apply_default_formatter'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/lib/rubocop/cli.rb:26:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/bin/rubocop:14:in `block in <top (required)>'
/opt/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:294:in `realtime'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/rubocop-0.39.0/bin/rubocop:13:in `<top (required)>'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/cookstyle-0.0.1/bin/cookstyle:13:in `load'
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/cookstyle-0.0.1/bin/cookstyle:13:in `<top (required)>'
/opt/chefdk/bin/cookstyle:16:in `load'
/opt/chefdk/bin/cookstyle:16:in `<main>'

cookstyle complaining about a missing comma after last item in a hash

I was running cookstyle on my cookbook and got an offense as shown below:

My attributes/default.rb contains:

default['cookbook_name']['site_details'] = {
  iis_path: 'Test',
  app_pool_name: 'Test',
  physical_path: 'c:\inetpub\Test'
}

when I run cookstyle its throwing below error:

Offenses:
attributes/default.rb:4:3: C: Put a comma after the last item of a multiline hash.
physical_path: 'c:\inetpub\Test'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

when I run cookstyle -a, it appends a "," after line 4 which don't make any sense and breaks json

default['cookbook_name']['site_details'] = {
  iis_path: 'Test',
  app_pool_name: 'Test',
  physical_path: 'c:\inetpub\Test',
}

Could you please take a look at this issue.

Put a comma after the last item of a multiline hash.

Why does cookstyle suggest to put comma after the last hash element?
rubocop suggest to remove comma after last element.

Desired style by cookstyle:

default['cookbook_name']['some_hash'] = {
  'attr01' => 'value01',
  'attr02' => 'value02',
  'attr03' => 'value03',
}

Desired style by rubocop:

default['cookbook_name']['some_hash'] = {
  'attr01' => 'value01',
  'attr02' => 'value02',
  'attr03' => 'value03'
}

version

  • Cookstyle 2.1.0
  • RuboCop 0.49.1

"Parser::Source::Rewriter is deprecated."

Getting the following output about Parser::Source::Rewriter being deprecated:

$ /opt/chefdk/bin/cookstyle --auto-correct
Inspecting 55 files
Parser::Source::Rewriter is deprecated.
Please update your code to use Parser::Source::TreeRewriter instead
.......................................................

55 files inspected, no offenses detected

Other possibly helpful information:

$ /opt/chefdk/bin/cookstyle --version
Cookstyle 2.1.0
  * RuboCop 0.49.1
$ /opt/chefdk/bin/chef --version
Chef Development Kit Version: 2.5.3
chef-client version: 13.8.5
delivery version: master (73ebb72a6c42b3d2ff5370c476be800fee7e5427)
berks version: 6.3.1
kitchen version: 1.20.0
inspec version: 1.51.21

Conflicting Ruby Syntax Checking

I found that Rubocop and Cookstyle often don't agree on how to do ruby syntax by default. For example, one that flaps is the Avoid comma after the last item of a hash cop.

Given a hash of:

{
  foo: 'bar',
  foo2: 'bar2'
}

Cookstyle wants to correct this syntax to the following:

{
  foo: 'bar',
  foo2: 'bar2',
}

Then when I run rubocop again with the default cops, it wants to take the trailing comma back out, and round and round we go.

I really don't care which standard is decided on but it would be great to have them both reflect the same rule here since they are directly conflicting at this point. In my opinion, I'm not convinced everyone should be required to create a .rubocop.yml in every cookbook they are working on to address this one or other such conflicting rules going forward but then again, that is my opinion..

What is the greater opinion on "choosing" or "not choosing" between rubocop and cookstyle? Should I use one to rule them all from a syntax perspective? It is pretty clear that Cookstyle is trying to solve a very similar issue as Rubocop but from a Chef angle. If it is not a full replacement, would you advise just using one anyhow? Thanks for your time in advance.

Getting "Deprecated pattern style, Inspecting 0 files" while running cookstyle . for a cookbook

While running cookstyle . on cookbook, I run into below warnings. As a result of this the test against cookbook to check code style doesn't run. For same cookbook, cookstyle works on a diff machine. Is there machine specific which I need to check?

Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Warning: Deprecated pattern style 'C:/chef-repo/cookbooks/couchbase/*' in C:/chef-repo/cookbooks/couchbase/.rubocop.yml
Inspecting 0 files```

Chef version from my machine - 

$ chef --version
Chef Development Kit Version: 0.14.25
chef-client version: 12.10.24
berks version: 4.3.3
kitchen version: 1.8.0

Add check for hash property on launchd resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

The hash property in the launchd resource was replaced with plist_hash.

What it would trigger on:

A launchd resource with a hash property

What it would autocorrect to if applicable

Replace hash with plist_hash

Detect a chef_handler resource with the supports property

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

We renamed the supports property to type to avoid confusion. We should autocorrect this anywhere we find it.

What it would trigger on:

chef_handler 'whatever' do
  supports 'foo'
end

What it would autocorrect to if applicable

chef_handler 'whatever' do
  type 'foo'
end

See: https://github.com/chef/chef/blob/master/lib/chef/resource/chef_handler.rb#L47

Autocorrect old Berkshelf source lines

Describe the new cop:

We should help out IT by updating Berksfiles to the latest URL

What it would trigger on:

In ./Berksfile:

source "https://supermarket.getchef.com"

source 'http://community.opscode.com/api/v3'

source 'https://api.berkshelf.com'

What it would autocorrect to if applicable

source 'https://supermarket.chef.io'

Detect if respond_to? in metadata

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

respond_to? in metadata is not required with Chef 13 or later.

What it would trigger on:

chef_version '>= 12.14' if respond_to?(:chef_version)
issues_url 'https://github.com/alaskaairlines/aag_infoblox/issues' if issues_url?(:chef_version)
source_url 'https://github.com/alaskaairlines/aag_infoblox' if respond_to?(:source_url)

What it would autocorrect to if applicable

chef_version '>= 12.14'
issues_url 'https://github.com/alaskaairlines/aag_infoblox/issues'
source_url 'https://github.com/alaskaairlines/aag_infoblox'

DoubleNegation cop and only_if { !!string } use case

see chef/chef#5581

TL;DR

resource "dummy" do
   not_if {  node['setting'] } 
end

throws an chef deprecation warning, however some use cases just exactly want to do that.

In chef/chef#5581 there was the suggestion to useโ€ฆ

resource "dummy" do
   not_if { !!node['setting'] } 
end

โ€ฆ however this currently triggers the Style/DoubleNegation cop.

Chef Development Kit Version: 1.2.22
chef-client version: 12.19.36
delivery version: master (0b746cafed65a9ea1a79de3cc546e7922de9187c)
berks version: 5.6.4
kitchen version: 1.16.0
chef -v  8,91s user 1,68s system 93% cpu 11,314 total

โ€ฆ

chef exec cookstyle acme_persistence.rb  -D
Inspecting 1 file
C

Offenses:

acme_persistence.rb:118:17: C: Style/DoubleNegation: Avoid the use of double negation (!!).
      only_if { !!item['crt'] }

โ€ฆ

Add a check for compile_time on chef_gem resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

A chef_gem resource should always have the compile_time resource set to true or false:

chef_gem "etcd" do
  compile_time true
end

Can the `-r` be moved into `.rubocop.yml` somehow?

My editors, etc. all are configured to use rubocop. Normally, I change the behavior of rubocop by modifying the .rubocop.yml.

Is there a way to tell rubocop to use cookstyle from the .rubocop.yml file?

parentheses in the method call but there is no method call

So I have a cron resource:

cron 'psquery upload' do
  action node.tags.include?('psquery-upload') || node['wp_onewise']['dirty_said_cron']['psquery-upload'] ? :create : :delete
  minute '0'
  hour '23'
  user 'root'
  command "#{gdriveroot}/Gdriveuploader/query.bash"
end

Which works, but cookstyle is like "Use parentheses in the method call to avoid confusion about precedence. "

If I had to guess, it's saying that I'm using all sorts of operators and to avoid and concerns I should group them explicitly. Easy enough

action (node.tags.include?('psquery-upload') || node['wp_onewise']['dirty_said_cron']['psquery-upload']) ? :create : :delete

rspec is still happy, but cookstyle is now unhappy about this:

interpreted as grouped expression.

cookstyle --version
Cookstyle 0.0.1

  • RuboCop 0.39.0

cat /opt/chefdk/version-manifest.txt
chefdk 0.18.30

fail-level not honored

Version: 4.0.0
Environment: MacOS, installed via Ruby gems.

Scenario:

Cookstyle as support for --fail-level RuboCop argument.. But that argument is useless without --display-only-fail-level-offenses, and cookstyle lacks support for it.

Steps to Reproduce:

$ cookstyle --fail-level W --display-only-fail-level-offenses cookbooks/myawesomecookbook/

Expected Result:

I expect that cookstyle would honor the level i set and only display offenses that are set by argument --fail-level

Actual Result:

invalid option: --display-only-fail-level-offenses
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rubocop-0.55.0/lib/rubocop/options.rb:21:in `parse'
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rubocop-0.55.0/lib/rubocop/cli.rb:37:in `run'
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rubocop-0.55.0/bin/rubocop:13:in `block in <top (required)>'
/opt/chefdk/embedded/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/rubocop-0.55.0/bin/rubocop:12:in `<top (required)>'
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/cookstyle-3.0.2/bin/cookstyle:13:in `load'
/opt/chefdk/embedded/lib/ruby/gems/2.5.0/gems/cookstyle-3.0.2/bin/cookstyle:13:in `<top (required)>'
/usr/local/bin/cookstyle:306:in `load'
/usr/local/bin/cookstyle:306:in `<main>'

Add a check for the easy_install resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

We removed this resource in Chef 13

What it would trigger on:

Any usage of easy_install

What it would autocorrect to if applicable

N/A

cookstyle -a for windows rewrites line endings of original file

Using cookstyle -a on a file with unix style (LF) endings adds CRLFs into the file, resulting in "carriage return detected" messages.

Version info:
Cookstyle 1.3.0

  • RuboCop 0.47.1

Chef Development Kit Version: 1.3.43
chef-client version: 12.19.36
delivery version: master (dd319aa632c2f550c92a2172b9d1226478fea997)
berks version: 5.6.4
kitchen version: 1.16.0

Detect old Chef::Platform methods usage

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

We removed many old Chef::Platform methods in Chef 13

What it would trigger on:

resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = Chef::Platform.provider_for_resource(resource, :create)

resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = Chef::Platform.find_provider("ubuntu", "16.04", resource)

resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = Chef::Platform.find_provider_for_node(node, resource)

What it would autocorrect to if applicable

resource = Chef::Resource::File.new("/tmp/foo.xyz", run_context)
provider = resource.provider_for_action(:create)

apt_repository key property should be an array

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

We coerce these into array anyways. They should just be arrays in code

What it would trigger on:

apt_repository '3cxpbx' do
  uri 'http://downloads-global.3cx.com/downloads/debian'
  distribution 'stretch main'
  key 'http://downloads-global.3cx.com/downloads/3cxpbx/public.key'
  cache_rebuild true
  action :add
end

What it would autocorrect to if applicable

apt_repository '3cxpbx' do
  uri 'http://downloads-global.3cx.com/downloads/debian'
  distribution 'stretch main'
  key ['http://downloads-global.3cx.com/downloads/3cxpbx/public.key']
  cache_rebuild true
  action :add
end

Add cop to remove use_inline_resources

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

use_inline_resources is the default in Chef now and we should remove it if we find it

What it would trigger on:

use_inline_resources

use_inline_resources if defined?(use_inline_resources)

What it would autocorrect to if applicable

Just delete it

safe navigation operator

I would like to enable this nil checking syntax:

admins = node['maas']&.key?('admin_name') ? Array(node['maas']['admin_name']) : data_bag('metal_admins')

note the &. after the node['maas'] It essentially says if node['maas'] is nil, discontinue this expression and return nil.

This is the same as the elvis operator in other languages. (e.g. ?. in c#)

adding a '.rubocop.yml' to my project with:

AllCops:
  TargetRubyVersion: 2.4

effectively enables the use of &. however it introduces new cookstyle errors of recipes/default.rb:1:1: C: Missing magic comment # frozen_string_literal: true. in every other file in my cookbook. Now that chef 12 is EOL, all supported versions of chef are ruby 2.3+, of which, ruby 2.3 was the introduction of this operator.

I don't know how big of an issue that frozen_string_literal error is - if there were a PR to update the ruby version, could this error be suppressed at the same time without repurcussions?

otherwise, all of the code generators would need updated to include that 'frozen_string_literals' in all of their files in order to accept this update.

The same remains true if I use TargetRubyVersion: 2.3

Disable Lint/ParenthesesAsGroupedExpression

test.rb:4:17: W: Lint/ParenthesesAsGroupedExpression: (...) interpreted as grouped expression.
  etcd_key_value ({

it's trying to get the space between the property and the parenthesis removed, but the message is terrible and that's probably bad form for a cookbook anyway

Remove `provides` in the metadata.rb file

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

provides doesn't make sense in the metadata.rb file anymore. We should remove these.

What it would trigger on:

provides 'account::user'

What it would autocorrect to if applicable

Just delete it

Detect allow_downgrades property on the dnf_package resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

dnf_package does not support the allow_downgrades property.

What it would trigger on:

Any dnf_package resource with an allow_downgrades property

What it would autocorrect to if applicable

Remove the property

Detect usuage of dsl_name method in resources

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

dsl_name was removed in Chef 13. Make sure folks aren't using it anymore

What it would trigger on:

my_resource = MyResource.dsl_name

What it would autocorrect to if applicable

my_resource = MyResource.resource_name

Detect usage of erl_call resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

erl_call was removed in Chef 14

What it would trigger on:

Any usage of the erl_call resource

What it would autocorrect to if applicable

N/A

Alert on usage of new_resource.updated_by_last_action in resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

This doesn't do what folks think it does anymore. We should make sure they're aware.

What it would trigger on:

new_resource.updated_by_last_action

What it would autocorrect to if applicable

N/A

Detect usage of deprecated provider_base method in resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

The provider_base method was removed in Chef 13. We should detect anyone still using it.

What it would trigger on:

Resource.provider_base 

What it would autocorrect to if applicable

N/A: See https://docs.chef.io/deprecations_custom_resource_cleanups.html for instructions

Specifying cookbook path does not work

Version:

$ cookstyle --version
Cookstyle 4.0.0

  • RuboCop 0.62.0

Environment:

Docker Ruby 2.5

FROM ruby:2.5

Scenario:

Trying to specify a cookbook path with cookstyle doesn't recognize any cookbooks

Steps to Reproduce:

Verify cookbook is present:

$ ls site-cookbooks/
common-node

$ ls site-cookbooks/common-node/
Berksfile  LICENSE  Policyfile.rb  README.md  chefignore  metadata.rb  recipes 

Run cookstyle against directory:

$ cookstyle site-cookbooks/
Inspecting 0 files

0 files inspected, no offenses detected

Specifying a file works fine:

$ cookstyle site-cookbooks/common-node/metadata.rb
Inspecting 1 file
.

1 file inspected, no offenses detected

Expected Result:

Specifying cookbook directory/path works

Actual Result:

No cookbooks are recognized

Notes

Downgrading to Cookstyle 3.0.2 and RuboCop 0.55.0 is recognizing paths.

Detect invalid nil default in resource properties

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

Users cannot set a value to nil unless they explicitly set the property to accept nils

What it would trigger on:

property :my_nillable_property, String, default: nil

What it would autocorrect to if applicable

N/A

Detect usage of the :uninstall action in the chocolatey_package resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

:uninstall action was removed in Chef 14

What it would trigger on:

chocolatey_package 'nginx' do
  action :uninstall
end

What it would autocorrect to if applicable

chocolatey_package 'nginx' do
  action :remove
end

Fixup common mistaken supports platforms in metadata.rb

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

Users put a lot of garbage into the supports field in metadata.rb. We should clean that up when possible

What it would trigger on:

supports 'rhel'
supports 'opensuse'
supports 'darwin'

What it would autocorrect to if applicable

supports 'redhat'
supports 'opensuseleap'
supports 'mac_os_x'

Detect usage of build-essential::default recipe

Describe the new cop:

build_essential the resource is built into chef now. We should direct users to that.

What it would trigger on:

depends 'build-essential' #metadata
include_recipe 'build-essential::default'

What it would autocorrect to if applicable

build_essential 'Install compiler tools (build-essential)'

Detect usuage of Chef::REST

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

The Chef::REST class was removed in Chef 13

What it would trigger on:

Chef::REST.whatever

What it would autocorrect to if applicable

N/A

Detect lc_all property in the locale resource

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

As of Chef 16 the locale resource will no longer support the lc_all property

What it would trigger on:

Any usage of lc_all

What it would autocorrect to if applicable

Remove the property

Detect use of run_command helper

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

The run_command helper was removed in Chef 13.

What it would trigger on:

run_command(:command => "/sbin/ifconfig eth0")

What it would autocorrect to if applicable

shell_out!("/sbin/ifconfig eth0")

Remove casecmp vs downcase preference cop

I'm not sure a chef run has the speed requirements to make this enforcement worth it, considering it's change in the legibility of the cookbook. I would rather not be forced :)

# subjective clear
if node['jira']['flavor'].downcase == 'software'
  # blah
end

# subjectively unclear
if node['jira']['flavor'].casecmp('software') == 0
  # blah
end

# subjectively unclear
if !node['jira']['flavor'].casecmp('software')
  # blah
end

I acknowledge that this is somewhat personal tastes, but in my mind, I'd like chef recipes to be humanly legible to folks who aren't totally in-the-know on ruby speed-based optimization idiosyncrasies that prob don't matter in the context of a chef run :)

Provide basic validation of default values in resource properties

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

If someone sets a Hash or Array we should make sure those are allowed types for the propety

What it would trigger on:

property :my_property, [ String ], default: []

What it would autocorrect to if applicable

N/A

Replace epic_fail with ignore_failure

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

Epic fail was removed in Chef 14

What it would trigger on:

package 'foo' do
epic_fail true
end

What it would autocorrect to if applicable

package 'foo' do
ignore_failure true
end

Detect usage of old mixins

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

We removed several old mixin in Chef 14 that may be used in Chef code

What it would trigger on:

include Chef::Mixin::LanguageIncludeAttribute
include Chef::Mixin::RecipeDefinitionDSLCore
include Chef::Mixin::LanguageIncludeRecipe
include Chef::Mixin::Language
include Chef::DSL::Recipe::FullDSL

What it would autocorrect to if applicable

We may be able to just remove these. Confirm that with @lamont-granquist

Detect file expansion in the verify property

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

Expansion of the file property was removed in Chef 13.

What it would trigger on:

file '/etc/nginx.conf' do
  verify 'nginx -t -c %{file}'
end

What it would autocorrect to if applicable

file '/etc/nginx.conf' do
  verify 'nginx -t -c %{path}'
end

Fixup using name_attribute on a property

What category of cop is this?:

Please try to select as few as possible.

  • Deprecation - A cop that alerts to a deprecation in the Chef Infra Client
  • Correctness - A cop that alerts when incorrect coding behavior is being used
  • Sharing - A cop that alerts to missing functionality necessary for sharing cookboooks with others
  • Style - A cop that alerts to a style best practice
  • Simplification - A cop that alerts to ways code can be simplified through refactoring
  • Effortless - A cop that alerts on code that must be resolved to move to the Effortless pattern
  • Policyfiles - A cop that alerts on code that must be resolved to move to the Policyfiles pattern

Describe the new cop:

When people migrate a LWRP to a custom resource they often miss some of the attribute -> property migrations

What it would trigger on:

property :something, String, name_attribute: true

What it would autocorrect to if applicable

property :something, String, name_property: true

Cookstyle says 'Put a comma after the last item of a multiline hash'

It has been observed that for Cookstyle complains to put comma for multi line hash where as rubocop doesn't.

recipes/server.rb:12:24: C: Put a comma after the last item of a multiline hash.
ssl_verify_mode: :verify_none
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Is it some conflict with versions?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.