A set of custom checks used by the Blitz Backend Elixir team on top of the excellent ones included with Credo. We use these checks to catch errors, improve code quality, maintain consistency, and shorten pull request review times.
Check the moduledocs inside the check modules themselves for details on the individual checks.
Add Credo (required to run the checks) and BlitzCredoChecks to your project dependencies by adding the following to your mix.exs
defp deps do
[
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:blitz_credo_checks, "~> 0.1", only: [:dev, :test], runtime: false}
]
end
If you do not have one already in the root of your project, a default Credo configuration file .credo.exs
can be generated with
mix credo.gen.config
Add some or all of these checks under the checks key in .credo.exs
checks: [
# Custom checks
{BlitzCredoChecks.ConcurrentIndexMigrations, []},
{BlitzCredoChecks.DocsBeforeSpecs, []},
{BlitzCredoChecks.DoctestIndent, []},
{BlitzCredoChecks.ImproperImport, []},
{BlitzCredoChecks.LowercaseTestNames, []},
{BlitzCredoChecks.NoAsyncFalse, []},
{BlitzCredoChecks.NoDSLParentheses, []},
{BlitzCredoChecks.NoIsBitstring, []},
{BlitzCredoChecks.NoRampantRepos, []},
{BlitzCredoChecks.SetWarningsAsErrorsInTest, []},
{BlitzCredoChecks.StrictComparison, []},
{BlitzCredoChecks.TodosNeedTickets, ticket_url: "https://linear.app/company/issue/"},
{BlitzCredoChecks.UseStream, []},
# ... all the other checks that come with Credo
]
mix credo
This library also contains Mix.Tasks.CredoDiff
which can run Credo checks across the subset of files that differ from a branch like main
. This can be useful for incrementally improving the codebase through only applying certain checks on files that are currently being edited.
mix credo_diff --trunk main --name stricter_checks
See Mix.Tasks.CredoDiff
for more details.
We welcome contributions to this library. Bear in mind however that new checks can be very controversial as they have a large impact on developer experience. We therefore recommend that you open an issue to discuss a new check before beginning work on a new one.
- Consider opening an issue for discussion
- Fork and clone this repository on GitHub
- Install elixir and erlang versions with
asdf
asdf install
- Fetch dependencies
mix deps.get
- Run the test suite
mix check
- Use your work in another project
It is an excellent idea to not just write tests, but to also run your check against another codebase.
Include your cloned project under deps
in the mix.exs
of your other codebase
{:blitz_credo_checks, path: "/home/username/dev/blitz_credo_checks/"}
And fetch your dependencies to pull in the local version you are working on
mix deps.get
Are you looking for a new gig?? We're looking for mid-level to senior level developers to join our team and continue growing our platform while building awesome software!
Come join us at Blitz.gg