Bylaw.Credo.Check.Elixir.AppModuleAcronymCasing
(bylaw_credo v0.1.0-alpha.1)
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 high and works with any version of Elixir.
Explanation
App-owned module names should use uppercase acronym words such as API,
CSV, HTTP, JSON, LLM, and UUID.
Examples
Avoid:
defmodule MyAppWeb.Api.V1.ToolController do
alias MyApp.Accounts.TenantApiKey
alias MyApp.TestSupport.ExAwsHttpClient
alias MyApp.DatabaseCheck.UuidKeys
endPrefer:
defmodule MyAppWeb.API.V1.ToolController do
alias MyApp.Accounts.TenantAPIKey
alias MyApp.TestSupport.ExAwsHTTPClient
alias MyApp.DatabaseCheck.UUIDKeys
endMix task modules are exempt because the project intentionally keeps names
such as Mix.Tasks.Qa.
Notes
This check uses static AST analysis, so it favors clear source-level patterns over runtime behavior.
Configure :app_roots for the application module roots that should be checked.
Options
Configure options in .credo.exs with the check tuple:
%{
configs: [
%{
name: "default",
checks: [
{Bylaw.Credo.Check.Elixir.AppModuleAcronymCasing,
[
acronyms: ~w(API CSV HTTP JSON UUID),
app_roots: ~w(MyApp MyAppWeb),
exempt_prefixes: ~w(Mix.Tasks),
relative_roots: ~w(api admin)
]}
]
}
]
}:acronyms- Uppercase acronym words to enforce in app-owned module names.:app_roots- Absolute app module roots that should be checked. Defaults to an empty list, so consumer applications should configure their own roots.:exempt_prefixes- Module prefixes that should always be ignored.:relative_roots- Relative module roots to check inside app-owned modules.
Usage
Add this check to Credo's checks: list in .credo.exs:
%{
configs: [
%{
name: "default",
checks: [
{Bylaw.Credo.Check.Elixir.AppModuleAcronymCasing,
[
app_roots: ~w(MyApp MyAppWeb)
]}
]
}
]
}Check-Specific Parameters
Use the following parameters to configure this check:
:acronyms
Uppercase acronym words to enforce in app-owned module names.
This parameter defaults to ["API", "CSV", "HTTP", "JSON", "LLM", "UUID"].
:app_roots
Absolute app module roots that should be checked. Defaults to an empty list.
This parameter defaults to [].
:exempt_prefixes
Module prefixes that should always be ignored.
This parameter defaults to ["Mix.Tasks"].
:relative_roots
Relative module roots to check inside app-owned modules.
This parameter defaults to ["api"].
General Parameters
Like with all checks, general params can be applied.
Parameters can be configured via the .credo.exs config file.