Ensure that aliases are alphabetically ordered within their groups to maintain consistent code style and address Credo readability warnings.
Elixir code style conventions prefer that module aliases are alphabetically ordered within their groups. This improves code readability, maintainability, and consistency. Credo checks for this ordering and warns when aliases are not properly alphabetized.
defmodule Explorer.Migrator.HeavyDbIndexOperation.RenameTransactions do
# ❌ BAD: Aliases not alphabetically ordered
alias Explorer.Chain.Cache.BackgroundMigrations
alias Explorer.Migrator.{HeavyDbIndexOperation, MigrationStatus}
alias Explorer.Migrator.HeavyDbIndexOperation.Helper
alias Explorer.Migrator.HeavyDbIndexOperation.DropTransactionsIndex
alias Explorer.Repo
end
# In the above, "Helper" comes after "DropTransactionsIndex"
# alphabetically, but it's listed before it. Correct order should be:
# - DropTransactionsIndex (D < H)
# - Helper (H)
defmodule Explorer.Migrator.HeavyDbIndexOperation.RenameTransactions do
# ✅ GOOD: Aliases properly alphabetically ordered
alias Explorer.Chain.Cache.BackgroundMigrations
alias Explorer.Migrator.{HeavyDbIndexOperation, MigrationStatus}
# Within same group, ordered alphabetically:
# D comes before H comes before R
alias Explorer.Migrator.HeavyDbIndexOperation.DropTransactionsIndex
alias Explorer.Migrator.HeavyDbIndexOperation.Helper
alias Explorer.Repo
end
Aliases are grouped by their module depth and prefix. List all aliases by location:
Group 1: Single-level modules
- alias Explorer.Repo
Group 2: Multi-level modules from same prefix
- alias Explorer.Chain.Cache.BackgroundMigrations
- alias Explorer.Migrator...
Within each group, sort by:
For modules with the same prefix like:
Explorer.Migrator.HeavyDbIndexOperation.CreateTransactions...Explorer.Migrator.HeavyDbIndexOperation.DropTransactions...Explorer.Migrator.HeavyDbIndexOperation.HelperSort by the last component: Create... < Drop... < Helper
Rearrange the alias statements to match the alphabetical order determined in Step 2.
Run Credo to ensure no warnings remain:
mix credo --strict
# ❌ BEFORE
alias Explorer.Migrator.HeavyDbIndexOperation.Helper
alias Explorer.Migrator.HeavyDbIndexOperation.DropTransactionsIndex
# ✅ AFTER
alias Explorer.Migrator.HeavyDbIndexOperation.DropTransactionsIndex
alias Explorer.Migrator.HeavyDbIndexOperation.Helper
# ❌ BEFORE
alias Explorer.Repo
alias Explorer.Chain.Cache.BackgroundMigrations
alias Explorer.Migrator.{HeavyDbIndexOperation, MigrationStatus}
# ✅ AFTER
alias Explorer.Chain.Cache.BackgroundMigrations
alias Explorer.Migrator.{HeavyDbIndexOperation, MigrationStatus}
alias Explorer.Repo