Skip to content
🏷 A suite of Credo checks to enforce naming best practices in an Elixir project
Elixir Makefile Shell
Branch: master
Clone or download
Latest commit 9dcc1a6 Oct 24, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config Initial commit Apr 19, 2019
lib/credo_naming/check
priv/scripts Initial commit Apr 19, 2019
test Always exclude files named 'stdin' in Consistency.ModuleFilename check ( Oct 23, 2019
.credo.exs Always exclude files named 'stdin' in Consistency.ModuleFilename check ( Oct 23, 2019
.formatter.exs Initial commit Apr 19, 2019
.gitignore Initial commit Apr 19, 2019
.travis.yml Support umbrella apps (#1) Apr 26, 2019
CHANGELOG.md Update changelog Oct 24, 2019
LICENSE.md
Makefile Fix version parsing in Makefile Apr 23, 2019
README.md
mix.exs v0.4.1 Oct 24, 2019
mix.lock Add ex_doc in dependencies Apr 19, 2019

README.md



CredoNaming is a suite of checks to enforce naming best practices in an Elixir project.

Installation

Add the :credo_naming package to your mix.exs dependencies:

def deps do
  [
    {:credo_naming, "~> 0.4", only: [:dev, :test], runtime: false}
  ]
end

Usage

You just need to add the checks you want in your .credo.exs configuration file.

Avoid specific terms in module names

This check will raise an issue if specific terms are found in module names.

{CredoNaming.Check.Warning.AvoidSpecificTermsInModuleNames, terms: ["Manager", ~r/Helpers?/]}

Suppose you have a MyApp.ErrorHelpers module:

$ mix credo

┃  Warnings - please take a look
┃
┃ [W] ↘ `Helpers` is included in the list of terms to avoid in module names.
┃       Consider replacing it with a more accurate one.
┃       lib/my_app/error_helpers.ex:1:39 #(MyApp.ErrorHelpers)

With this check configuration for example, a module named MyApp.UserManager or MyApp.FormHelpers would not be allowed.

Ensure module/filename consistency

This check will raise an issue if the name of a module defined in a file does not match its filename.

{CredoNaming.Check.Consistency.ModuleFilename}

Suppose you have a lib/foo.ex file that defines a Bar module:

$ mix credo

┃ Consistency
┃
┃ [C] ↘ The module defined in `lib/foo.ex` is not named consistently with the
┃       filename. The file should be named either:
┃
┃       ["lib/bar/bar.ex", "lib/bar.ex"]
┃
┃       lib/foo.ex:1:11 #(Bar)

Exclusions

You can exclude files or paths with the excluded_paths option:

{CredoNaming.Check.Consistency.ModuleFilename, excluded_paths: ["test/support", "priv", "rel", "mix.exs"]}

Acronyms

The check converts module names to paths using PascalCase convention, which means that the file lib/myapp_graphql.ex is expected to define the module:

defmodule MyappGraphql do
end

If you want to define your own acronyms, you can do so using the acronyms option:

{CredoNaming.Check.Consistency.ModuleFilename, acronyms: [{"MyAppGraphQL", "myapp_graphql"}]}

Using this, the lib/myapp_graphql.ex file will expect to define the module:

defmodule MyAppGraphQL do
end

Contributors

License

CredoNaming is © 2019 Mirego and may be freely distributed under the New BSD license. See the LICENSE.md file.

The tag logo is based on this lovely icon by Vectors Point, from The Noun Project. Used under a Creative Commons BY 3.0 license.

About Mirego

Mirego is a team of passionate people who believe that work is a place where you can innovate and have fun. We’re a team of talented people who imagine and build beautiful Web and mobile applications. We come together to share ideas and change the world.

We also love open-source software and we try to give back to the community as much as we can.

You can’t perform that action at this time.