Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Credo

reading/deprecated_credo.livemd

Credo

Mix.install([
  {:jason, "~> 1.4"},
  {:kino, "~> 0.9", override: true},
  {:youtube, github: "brooklinjazz/youtube"},
  {:hidden_cell, github: "brooklinjazz/hidden_cell"}
])

Navigation

Home Report An Issue ExDocTypespec Drills

Credo

Credo is another static analysis tool which focuses on teaching and code consistency. It scans a project’s code for anti-patterns and provides suggestions to improve it’s quality and readability.

Your Turn

Install Credo in your math project by adding it to your dependencies in mix.exs. You can find the latest Credo version on hex.pm.

defp deps do
  [
      {:credo, "~> 1.6", only: [:dev, :test], runtime: false}
  ]
end

Ensure you install the new dependency.

$ mix deps.get

Then run the following command to see credo warnings.

$ mix credo
...
Analysis took 0.01 seconds (0.01s to load, 0.00s running 52 checks on 3 files)
3 mods/funs, found no issues.

Credo provides code suggestions that help you write idiomatic Elixir.

For example, Credo will warn you if you leave an IO.inspect/2 in your project as you probably don’t want to leave calls to IO.inspect/2 in your codebase.

Your Turn

Previously you converted a Math module into a mix project in the ExUnit with Mix section.

Add credo as a dependency to the project and leave an IO.inspect/2 call somewhere in your codebase.

Run mix credo and you should see a warning similar to the following.

$ mix credo
  Warnings - please take a look
┃
┃ [W] ↗ There should be no calls to IO.inspect/1.
┃       lib/math.ex:20:5 #(Math.test)

Please report incorrect results: https://github.com/rrrene/credo/issues

Analysis took 0.09 seconds (0.05s to load, 0.04s running 52 checks on 3 files)
4 mods/funs, found 1 warning.

Further Reading

Consider the following resource(s) to deepen your understanding of the topic.

Commit Your Progress

DockYard Academy now recommends you use the latest Release rather than forking or cloning our repository.

Run git status to ensure there are no undesirable changes. Then run the following in your command line from the curriculum folder to commit your progress.

$ git add .
$ git commit -m "finish Credo reading"
$ git push

We’re proud to offer our open-source curriculum free of charge for anyone to learn from at their own pace.

We also offer a paid course where you can learn from an instructor alongside a cohort of your peers. We will accept applications for the June-August 2023 cohort soon.

Navigation

Home Report An Issue ExDocTypespec Drills