OptimumCredo.Check.Warning.WebNamespaceInCore (OptimumCredo v0.5.0)

View Source

Basics

This check is disabled by default.

Learn how to enable it via .credo.exs.

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

Explanation

Core modules should not depend on the web namespace. Web code may use core modules, never the other way around.

Bad

# lib/my_app/drops.ex
MyAppWeb.Endpoint.broadcast("drops", "created", payload)

Good

# lib/my_app/drops.ex
Phoenix.PubSub.broadcast(MyApp.PubSub, "drops", {:created, payload})

The namespace is inferred from the path when web_namespace is not set. Use allowed_modules for deliberate exceptions. Dynamic modules and quote bodies are not inspected; lib/<app>/application.ex is skipped by default.

Check-Specific Parameters

Use the following parameters to configure this check:

:web_namespace

Web namespace such as "MyAppWeb" (or a list). Inferred from the path and module name when unset.

This parameter defaults to nil.

:allowed_modules

Web modules (and their children) that core code may reference.

This parameter defaults to [].

:allow_application

Skip lib/<app>/application.ex, which starts the endpoint.

This parameter defaults to true.

General Parameters

Like with all checks, general params can be applied.

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