{"id":13532958,"url":"https://github.com/chef/cookstyle","last_synced_at":"2025-06-25T22:32:48.876Z","repository":{"id":7838391,"uuid":"56622823","full_name":"chef/cookstyle","owner":"chef","description":"A linting tool that helps you to write better Chef Infra cookbooks and InSpec profiles by detecting and automatically correcting style, syntax, and logic mistakes in your code.","archived":false,"fork":false,"pushed_at":"2025-06-17T20:55:02.000Z","size":4917,"stargazers_count":112,"open_issues_count":115,"forks_count":53,"subscribers_count":30,"default_branch":"main","last_synced_at":"2025-06-20T15:01:11.615Z","etag":null,"topics":["chef","chef-infra","controls","cookbook","hacktoberfest","inspec","linting","policy-as-code","profile","recipes","rubocop"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chef.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-04-19T18:48:42.000Z","updated_at":"2025-06-17T20:55:06.000Z","dependencies_parsed_at":"2023-11-29T19:35:09.122Z","dependency_job_id":"f5f63911-66df-4965-bb97-f0d1432e2908","html_url":"https://github.com/chef/cookstyle","commit_stats":{"total_commits":1914,"total_committers":35,"mean_commits":54.68571428571428,"dds":0.5397074190177639,"last_synced_commit":"e7244d1d8c55ec0b81d7b14a16917727e9bee193"},"previous_names":[],"tags_count":571,"template":false,"template_full_name":null,"purl":"pkg:github/chef/cookstyle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef%2Fcookstyle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef%2Fcookstyle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef%2Fcookstyle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef%2Fcookstyle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chef","download_url":"https://codeload.github.com/chef/cookstyle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chef%2Fcookstyle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260967380,"owners_count":23090101,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chef","chef-infra","controls","cookbook","hacktoberfest","inspec","linting","policy-as-code","profile","recipes","rubocop"],"created_at":"2024-08-01T07:01:15.359Z","updated_at":"2025-06-25T22:32:48.828Z","avatar_url":"https://github.com/chef.png","language":"Ruby","readme":"# Chef Cookstyle - Chef Infra Cookbook and InSpec profile linting with autocorrection\n\n[![Build status](https://badge.buildkite.com/c086ffe05e32e4d61282b91ead96b3721590a59ed4360cf7ac.svg?branch=main)](https://buildkite.com/chef-oss/chef-cookstyle-main-verify)\n[![Gem Version](https://badge.fury.io/rb/cookstyle.svg)](https://badge.fury.io/rb/cookstyle)\n\n* **Umbrella Project**: [Chef Infra](https://github.com/chef/chef-oss-practices/blob/main/projects/chef-infra.md)\n* **[Project State](https://github.com/chef/chef-oss-practices/blob/main/repo-management/repo-states.md):** Active\n* **Issues [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/main/repo-management/repo-states.md):** 14 days\n* **Pull Request [Response Time Maximum](https://github.com/chef/chef-oss-practices/blob/main/repo-management/repo-states.md):** 14 days\n\nCookstyle is a [code linting](https://en.wikipedia.org/wiki/Lint_%28software%29) tool that helps you to write better Chef Infra cookbooks and InSpec profiles by detecting and automatically correcting style, syntax, logic, and security mistakes in your code.\n\nCookstyle is powered by the [RuboCop](https://www.rubocop.org) linting engine. RuboCop ships with over three-hundred rules, or cops, designed to detect common Ruby coding mistakes and enforce a common coding style. We've customized Cookstyle with a subset of those cops that we believe are perfectly tailored for cookbook development. We also ship **259 Chef Infra specific cops** that catch common cookbook coding mistakes, cleanup portions of code that are no longer necessary, and detect deprecations that prevent cookbooks from running on the latest releases of Chef Infra Client.\n\nFor complete usage documentation along with documentation for all the included cops see https://docs.chef.io/workstation/cookstyle/\n\n## Cookstyle vs. RuboCop\n\nHow does Cookstyle differ from RuboCop?\n\n#### Tailored for Cookbooks and Profiles\n\nCookbook and profile development differs from that of traditional Ruby software development, so we have tailored the list of built-in cops in RuboCop for cookbook development. For the most part, this means disabling cops deemed not useful for cookbook development. Occasionally, we've changed the configuration of a rule to enforce a different behavior altogether. We've also extended the base RuboCop package with a set of our own Chef Infra-specific cops. These cops are only found in Cookstyle and will help you to write more reliable and future-proof cookbooks.\n\nSee the current set of cops in [Cops Documentation](https://github.com/chef/cookstyle/blob/main/docs/cops.md)\n\n#### Stable\n\nRuboCop is an incredibly active project with new cops being introduced monthly. The new cops cause existing codebases to fail CI tests and force authors to constantly update their code. With Cookstyle, we update the RuboCop engine for bug and performance fixes, but we only change the set of cops that will fail tests once a year during Chef Infra's April major release. All new cops are introduced at RuboCop's \"refactor\" alert level, meaning they will alert to the screen as you run Cookstyle, but they won't fail a build. This stability means you are free to upgrade releases of Cookstyle without being forced to update your infrastructure code.\n\n## Cookstyle vs. Foodcritic\n\nCookstyle is the replacement for Foodcritic. For more information on why we decided to replace Foodcritic see our blog post [Goodbye Foodcritic](https://blog.chef.io/goodbye-foodcritic/)\n\n## Installation\n\nCookstyle is included in [Chef Workstation](https://downloads.chef.io/chef-workstation/). If you choose not to use the Chef Workstation package, you can still install Cookstyle manually using the instructions below.\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'cookstyle'\n```\n\nAnd then execute:\n\n```shell\nbundle\n```\n\nOr install it yourself as:\n\n```shell\ngem install cookstyle\n```\n\n## Usage\n\n### cookstyle Command\n\nUse this tool just as you would RuboCop, but invoke the `cookstyle` binary instead, which patches RuboCop to load cops from the cookstyle gem. For example:\n\n```shell\ncookstyle -D --format offenses\n```\n\n### Rake\n\nIn a Rakefile, the setup is similar, except you need to require the cookstyle library first:\n\n```ruby\nrequire 'cookstyle'\nrequire 'rubocop/rake_task'\nRuboCop::RakeTask.new(:cookstyle) do |task|\n  task.options \u003c\u003c '--display-cop-names'\nend\n```\n\n### From RuboCop\n\nRun RuboCop as normal, and simply add a `-r cookstyle` option when running:\n\n```sh\nrubocop -r cookstyle -D --format offenses\n```\n\n### guard-rubocop\n\nYou can use one of two methods. The simplest is to add the `-r cookstyle` option to the `:cli` option in your Guardfile:\n\n```ruby\nguard :rubocop, cli: \"-r cookstyle\" do\n  watch(%r{.+\\.rb$})\n  watch(%r{(?:.+/)?\\.rubocop\\.yml$}) { |m| File.dirname(m[0]) }\nend\n```\n\nAlternatively you could pass the path to Cookstyle's configuration by using the `Cookstyle.config` method:\n\n```ruby\nrequire \"cookstyle\"\n\nguard :rubocop, cli: \"--config #{Cookstyle.config}\" do\n  watch(%r{.+\\.rb$})\n  watch(%r{(?:.+/)?\\.rubocop\\.yml$}) { |m| File.dirname(m[0]) }\nend\n```\n\n### .rubocop.yml\n\nAs with RuboCop, any custom settings can still be placed in a `.rubocop.yml` file in the root of your project.\n\n### Testing Against Specific Chef Versions\n\nMany of the cops included in Cookstyle will autocorrect Chef Infra cookbook code in ways that will require fairly recent releases of Chef Infra Client in order to run those cookbooks. For example the `Chef/Modernize/UnnecessaryDependsChef14` cop will remove cookbook dependencies from your `metadata.rb` which are no longer necessary with Chef Infra Client 14+. This cop would be problematic if you ran it against your cookbooks, and had yet to upgrade your fleet of systems to Chef Infra Client 14+. For this reason you may want to configure Cookstyle to skip cops that would be destructive on older version of Chef Infra Client by setting.\n\nCookstyle now includes a new top-level configuration option TargetChefVersion. This new configuration option works similarly to RuboCop's TargetRubyVersion config option and allows you to specify a Chef Infra version that you want to target in your Cookstyle analysis. By setting the target version you disable incompatible cops and autocorrect from running. This allows you to gradually update your target version to allow stepped upgrades of Chef Infra Client such as 12.something -\u003e 12.latest -\u003e 13.latest -\u003e 14.latest -\u003e 15.latest.\n\nExample .rubocop.yml config specifying a TargetChefVersion of 14.0:\n\n```yaml\nAllCops:\n  TargetChefVersion: 14.0\n```\n\n## Getting Involved\n\nWe'd love to have your help in developing Cookstyle. See our [Contributing Guide](https://github.com/chef/chef/blob/main/CONTRIBUTING.md) for more information on contributing to Chef projects. There's also a [Developer Guide](./DEVELOPER_GUIDE.md) for Cookstyle that outlines how the configs work and how you can upgrade the RuboCop engine.\n\n## License and Copyright\n\nCopyright 2016-2021, Chef Software, Inc.\n\n```\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","funding_links":[],"categories":["Awesome Ruby CLIs"],"sub_categories":["Linting"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchef%2Fcookstyle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchef%2Fcookstyle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchef%2Fcookstyle/lists"}