How to Use Cookstyle to Autocorrect Style Issues

Featured image for sharing metadata for article

Cookstyle is the primary linting tool for Chef cookbooks, and is a great way of picking up on common issues - be they style, or more substantial like antipatterns that were previously tracked using (the now deprecated) Foodcritic.

I spotted earlier that someone was searching on my site to find out how to fix things automagically, so I thought I'd write a quick post for it. It also turns out that I've been meaning to write about this for over two years!.

Cookstyle is based on Rubocop, which provides the super handy -a flag to autocorrect any cops it can do:

cookstyle -a .
# ...
11 files inspected, 36 offenses detected, 34 offenses corrected, 1 more offense can be corrected with `rubocop -A`

And it'll fix as much as it can do!

You may see that it may not be able to fix everything, as there are some unsafe changes it won't perform by default. I'd recommend doing these manually, but if you've reviewed them and seem happy, you can resolve them with:

cookstyle -A .

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #chef #ruby #chefdk #chef-workstation #cookstyle.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.