Goodbye, Foodcritic

All good things come to an end, and now is the time to say goodbye to Foodcritic. In 2011, Andrew Crump did the Chef community a huge service by writing what would become the defacto standard code linter for Chef Cookbooks. Foodcritic was a ground up code linting tool built especially for Chef Cookbooks. Since 2011, 123 cookbook rules have shipped in Foodcritic and countless Chef users have been aided in writing better cookbooks.

Fast forward to 2019, and Foodcritic’s age is becoming increasingly apparent. There is an ever increasing backlog of issues ranging from requests for autocorrection to dozens of issues surrounding rule false positives. It became apparent that a radical change was necessary for the Chef community to continue to have a useful linting tool. From that a “wish list” of features for a modern linting tool was put together so we could understand the work involved in updating Foodcritic.

Modern Chef Linting Wishlist:

  • The ability to auto correct detected offenses.
  • A configuration system that would allow excluding rules on individual files and changing rule behavior based on configuration (FC001!).
  • Different output formats to allow better plugging Foodcritic into CI tools.
  • Varying offense levels to allow for the creation of rules that alert, but don’t fail builds.
  • A better system for detecting cookbooks and files to scan.
  • A simpler system for writing rules that avoids the need for XPath.

With our wish list in hand, it was fairly obvious that the linting tool we wanted to build had already been built. RuboCop is a modern Ruby linting tool with a mature codebase and large contributor base. In fact RuboCop is already being used in the Chef community to lint Cookbook Ruby code via the Cookstyle tool. RuboCop meets nearly all of our needs out of the box and seemed like the perfect fit as we could extend Cookstyle to include Chef linting in addition to Ruby linting. All that was needed was to teach RuboCop a few things about cookbooks.

In 2016 Noah Kantrowitz wrote a proof of concept Rubocop plugin implementing several existing Foodcritic rules. It worked quite well, but with 123 existing rules in Foodcritic the idea of porting all of Foodcritic was daunting and the proof of concept was shelved. Fast forward to 2019 once again, and Chef has picked up that work to extend Cookstyle to lint cookbooks. As of September 2019, Cookstyle already includes nearly as many rules as Foodcritic and also features all the modern functionality one would expect, which looks nearly identical to our wishlist:

  • Robust configuration system
  • Varying cop offense levels
  • Autocorrection of offenses
  • Low false positive rate
  • Machine readable output formats
  • Fast cookbook scanning via parallelism
  • Modern cops targeting new Chef Infra usage patterns
  • A simpler querying language for writing rules and hundreds of Ruby helpers

At this point we consider the Foodcritic project sunsetted and suggest all users move cookbook linting to Cookstyle. Cookstyle with Chef cookbook support ships in Chef Workstation 0.9+ and ChefDK 4.4+. If you’d like to checkout the project or request new cops visit github.com/chef/cookstyle

Thanks.

Tim Smith (tas50)

Tim Smithh

Tim was the Product Manager for Chef Infra.