Skip to main content

alphabetically-ordered-aliases

Ensure that aliases are alphabetically ordered within their groups to maintain consistent code style and address Credo readability warnings.

설치로 이동

소스 정보

저장소
blockscout/blockscout
최근 소스 활동
2026년 3월 6일 16:27
감지된 SKILL.md 언어
영어
스타
4,691
포크
3,174

설치 방법

기본적으로 소스를 먼저 확인하는 Prompt가 선택됩니다. 직접 명령으로 전환하거나 로컬 사본을 다운로드할 수도 있습니다.

소스 파일 검토

설치 여부를 결정하기 전에 SKILL.md와 SkillsMP에 표시된 보조 파일을 읽어 보세요.

SKILL.md 표시 중

SKILL.md
소스 지침 · 읽기 전용 미리보기
name
alphabetically-ordered-aliases
description
Ensure that aliases are alphabetically ordered within their groups to maintain consistent code style and address Credo readability warnings.
## Overview 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. ## When to Use - When addressing Credo warning: "The alias is not alphabetically ordered among its group" - When organizing module aliases at the top of a file - When multiple aliases from related modules are defined together - When refactoring code to improve consistency and readability ## Anti-Patterns (Avoid These) ```elixir 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) ``` ## Best Practices (Use These) ```elixir 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 ``` ## How to Implement ### Step 1: Identify alias groups 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... ``` ### Step 2: Sort alphabetically within each group Within each group, sort by: 1. The full module path alphabetically 2. Consider the last component of the path when the prefix is the same For modules with the same prefix like: - `Explorer.Migrator.HeavyDbIndexOperation.CreateTransactions...` - `Explorer.Migrator.HeavyDbIndexOperation.DropTransactions...` - `Explorer.Migrator.HeavyDbIndexOperation.Helper` Sort by the last component: `Create...` < `Drop...` < `Helper` ### Step 3: Reorder in code Rearrange the alias statements to match the alphabetical order determined in Step 2. ### Step 4: Verify with Credo Run Credo to ensure no warnings remain: ```bash mix credo --strict ``` ## Example Violations and Fixes ### Violation 1: Helper before DropTransactions ```elixir # ❌ BEFORE alias Explorer.Migrator.HeavyDbIndexOperation.Helper alias Explorer.Migrator.HeavyDbIndexOperation.DropTransactionsIndex # ✅ AFTER alias Explorer.Migrator.HeavyDbIndexOperation.DropTransactionsIndex alias Explorer.Migrator.HeavyDbIndexOperation.Helper ``` ### Violation 2: Mixed ordering in group ```elixir # ❌ 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 ``` ## Related Skills - [Code Formatting](../code-formatting/SKILL.md) - Run after applying alias ordering fixes - [Alias Nested Modules](../alias-nested-modules/SKILL.md) - Define aliases for nested modules ## References - [Credo Readability.AliasOrder](https://hexdocs.pm/credo/Credo.Check.Readability.AliasOrder.html) - [Elixir Naming Conventions](https://hexdocs.pm/elixir/naming-conventions.html)
GitHub에서 보기