Writing a Custom Credo Check in Elixir: A Guide for Developers
Static code analysis is an important tool to ensure a project meets the right code standards and quality. In Elixir, the most popular package for this is Credo. Not only does it offer dozens of pre-made checks, but it also allows you to create your own. This article provides a step-by-step guide on how to write a custom Credo check. It covers topics such as enabling the check in the Credo config and making it user-friendly. The author explains the importance of creating Credo checks and provides real-world examples with an Elixir app. The article also delves into the anatomy of a Credo check, discussing categories, priorities, and explanations. It highlights the use of the use Credo.Check
module and the run
function as the entry point for the check. The author emphasizes the use of Credo.Code.to_tokens
to parse source file contents and identify issues. This comprehensive guide is a valuable resource for Elixir developers looking to enhance their code analysis with custom Credo checks.