Linters
Learn and practice linters, specifically Elixir's main linter-Credo, in this lesson.
We'll cover the following
Credo: linter as teacher
Linters are important because they automate tedious style and code quality checks. Linter rules don’t exist in a vacuum. The coding rules come from the language community. As the language evolves, so does the linter. One of the most useful libraries for code consistency is René Föhring’s Credo. It’s a linter like Ruby’s Rubocop or JSLint for JavaScript, but as it proclaims in the tagline on GitHub, it’s a linter “with a focus on code consistency and teaching.” That aim is what makes Credo so interesting.
With a standard linter, you might get some warning or suggestion, and instead of understanding the issue, you make the change and move on. The linter helps improve the quality of the code, but it doesn’t give the developer much context as to why these changes are necessary.
Credo, too, tells you “what”, but also answers “why”.
Let’s look at a contrived simple
Note: Mix is an Elixir executable. This means that in order to run mix, we need to have both mix and elixir executables in your PATH. That’s what happens when Elixir is installed.
Elixir has a package manager called Hex. Every time we add a dependency to the project, Hex is responsible for downloading it. Many packages in Hex are named after the package domain followed by an _ex
prefix, such as html_sanitize_ex
, kafka_ex
, and many others.
Our application will “hexify” library names by appending _ex
to the given string unless one already exists. We have already created the application for you, but if you want to make one locally, you can create it using the command:
Get hands-on with 1400+ tech skills courses.