Flag problems in your Chef cookbooks using Foodcritic - nshenry03/chef-repo GitHub Wiki

Foodcritic has two goals:

  • To make it easier to flag problems in your Chef cookbooks that will cause Chef to blow up when you attempt to converge. This is about faster feedback. If you automate checks for common problems you can save a lot of time.
  • To encourage discussion within the Chef community on the more subjective stuff - what does a good cookbook look like? Opscode have avoided being overly prescriptive which by and large I think is a good thing. Having a set of rules to base discussion on helps drive out what we as a community think is good style.

Foodcritic should be installed by default when you run 'bundle install' from your chef repo. You can then test a cookbook like this:

foodcritic [cookbook_path]

So, for example, if I wanted to test my 'base-logic' cookbook, I would simply run: foodcritic ../cookbooks/base-logic.

If you want to be sure it works, you can try renaming your README.md file as this will throw an error... Click here for a full list of rules.

If you want, you can add additional 'rules' to test cookbooks with:

mkdir foodcritic
git submodule add [email protected]:etsy/foodcritic-rules.git foodcritic/etsy
git submodule add [email protected]:customink-webops/foodcritic-rules.git foodcritic/customink
git commit -m "Add etsy and customink foodcritic submodules" foodcritic/etsy foodcritic/customink .gitmodules
git push origin master

You can now test cookbooks with foodcritic -I foodcritic/* [cookbook_path]

NOTES:

Fetch submodules after cloning a repository:

git submodule update --init

Pull upstream main repo changes and update submodule contents:

git submodule update