Rbtz.CredoChecks.Design.CustomAliasInRouterScope (rbtz_credo_checks v0.2.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

Forbids manual alias statements inside Phoenix scope blocks in router files.

scope/2 and scope/3 already prefix every controller and LiveView reference with the scope's alias argument. Layering an explicit alias on top defeats that prefixing, makes route lookup harder for tools, and diverges from the rest of the project's router conventions.

The check fires only on files matching *_router.ex or **/router.ex.

Bad

scope "/admin", MyAppWeb.Admin do
  alias MyAppWeb.Admin.Users
  get "/users", Users.IndexController, :index
end

Good

scope "/admin", MyAppWeb.Admin do
  get "/users", Users.IndexController, :index
end

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.