ForgeCredoChecks.NamespaceTrespassing (forge_credo_checks v0.7.0)

Copy Markdown View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

This check has a base priority of normal and works with any version of Elixir.

Explanation

Do not define your modules inside a dependency's namespace.

Why

Defining defmodule Phoenix.MyThing (or any module whose top namespace belongs to a library you depend on) trespasses on that library's namespace. It reads as if the module ships with the dependency, invites collisions when the dependency later adds a module of the same name, and hides the module from your application's own namespace where readers look for it. Keep your modules under your application's namespace.

Bad

defmodule Phoenix.Helpers do
defmodule Ecto.MyType do

Good

defmodule MyApp.Phoenix.Helpers do
defmodule MyApp.EctoTypes.MyType do

Configuration

namespaces lists the reserved top namespaces. A module defined with one of them as its first segment flags. The default omits Mix, because Mix.Tasks.* is the required home for custom Mix tasks.

Check-Specific Parameters

There are no specific parameters for this check.

General Parameters

Like with all checks, general params can be applied.

Parameters can be configured via the .credo.exs config file.