-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #965 from dafyddcrosby/main
Simplify setting default cops
- Loading branch information
Showing
7 changed files
with
56 additions
and
6,215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,21 @@ | ||
## How It Works | ||
|
||
The project itself is a derivative of [finstyle](https://github.com/fnichol/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](https://github.com/chef/cookstyle/blob/main/Rakefile) the upstream configuration to determine if any breaking style or lint cops were added/dropped/reversed/etc. | ||
The project itself is a derivative of [finstyle](https://github.com/fnichol/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. | ||
|
||
## NOTE CAREFULLY ABOUT UPDATING COOKSTYLE | ||
|
||
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 Configuration Files | ||
|
||
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: | ||
|
||
[upstream.yml](https://github.com/chef/cookstyle/blob/main/config/upstream.yml) | ||
|
||
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. | ||
|
||
[disable_all.yml](https://github.com/chef/cookstyle/blob/main/config/disable_all.yml) | ||
|
||
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. | ||
## Cookstyle Configuration File | ||
|
||
[cookstyle.yml](https://github.com/chef/cookstyle/blob/main/config/cookstyle.yml) | ||
|
||
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. | ||
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. The file takes an allowlist approach to cops, with AllCops having DisabledByDefault as true. If a rule is not explicitly enabled, it will not run. | ||
|
||
`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. | ||
|
||
## Updating the RuboCop Engine | ||
|
||
Cookstyle ships with a rake task to aid in updating RuboCop releases. Start by updating the RuboCop version in the [lib/cookstyle/version.rb](https://github.com/chef/cookstyle/blob/main/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. | ||
Before updating the engine, save a copy of the current engine's rule output with `cookstyle --show-cops`. Start by updating the RuboCop version in the [lib/cookstyle/version.rb](https://github.com/chef/cookstyle/blob/main/lib/cookstyle/version.rb) file. Then run `bundle update` to update the RuboCop gem. Confirm the engine is updated with `cookstyle --version`. Then save the output from another run of `cookstyle --show-cops` and compare the older output to the new output using `diff` and `shasum` to confirm that there are no new/unexplained rules being added or removed between the engine releases. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
inherit_from: | ||
- upstream.yml | ||
- disable_all.yml | ||
- cookstyle.yml |
Oops, something went wrong.