The project itself is a derivative of finstyle, but starts with all cops (rules) disabled. Cookstyle has a direct dependency on one specific version of RuboCop (at a time), and patches it to load the upstream configuration and custom set of cop updates. When a new RuboCop release comes out, this library can bump the pinned RuboCop version dependency and re-vendor the upstream configuration to determine if any breaking style or lint cops were added/dropped/reversed/etc.
Cookstyle is designed to allow bumping the RuboCop engine while keeping backwards compatibility with the config and not requiring all the cookbooks to update. This isn't always possible since many bugfixes catch new issues in cookbooks, but we do our best to prevent constantly linting of large codebases.
Enabling or disabling any new cops in this file must be accompanied by comments demonstrating why the change should be made. Keep in mind anything you add here causes Chef users significant work, so make sure it's worth it.
Cookstyle works by overwriting RuboCop's standard config with our own default.yml file. This file sources three other files to provide the final layer-cake that is Cookstyle:
The upstream.yml config file is a vendored copy of the out-of-the-box RuboCop config from the version of the engine we're using. It's necessary to start with this file as it includes cop metadata like descriptions and also includes the actual configuration details for each cop.
The disable_all.yml is loaded after the upstream.yml config in order to disable all of the cops that ship with RuboCop. This ensures that we only turn on the cops we want. Since updating the RuboCop engine also updates this file, we'll never introduce a new cop just by updating the engine.
The cookstyle.yml config file is the enabled.yml file from RuboCop 0.37.2 combined with a sprinkling of cops released in the dozens of RuboCop releases since then as well as configs for all our own Chef cops. All cops enabled since 0.37.2 include a comment or link to a PR so you can see the justification for adding the cop.
NOTE
: The cookstyle.yml
file was generated by hand and it may be necessary to edit that file (again by hand) to resolve issues with later RuboCop engines changing cop names or behavior.
Cookstyle ships with a rake task to aid in updating RuboCop releases. Start by updating the RuboCop version in the lib/cookstyle/version.rb file. Then run bundle update
and bundle exec rake vendor
to update the upstream.yml
and disable_all.yml
files. You'll want to check the changes in the upstream.yml
file. Updating this file often requires updating the configs in the cookstyle.yml to prevent warnings when running Cookstyle.