go-codemod

작성자: github

gh aw fix 명령어를 위한 Go 코드모드를 구현하고 테스트합니다.

npx skills add https://github.com/github/gh-aw --skill go-codemod

Go Codemod Implementation Guide

Use this skill when adding or updating codemods used by gh aw fix.

Understand the fix pipeline first

  1. Review pkg/cli/fix_command.go to understand execution flow:
    • codemods are loaded once via GetAllCodemods()
    • each codemod is applied in registry order
    • frontmatter is re-parsed before each codemod
    • codemods must return (newContent, applied, error) and be safe for no-op input
  2. Review the codemod registry in pkg/cli/fix_codemods.go.
  3. Review helper utilities in pkg/cli/yaml_frontmatter_utils.go and reusable codemod helper constructors in pkg/cli/codemod_factory.go.

Implementation steps

  1. Create a new codemod file in pkg/cli/ named codemod_<feature>.go.
  2. Add a package logger with logger.New("cli:codemod_<feature>").
  3. Implement get<Feature>Codemod() Codemod and populate all metadata fields:
    • ID (stable, unique)
    • Name (human-readable)
    • Description (clear migration behavior)
    • IntroducedIn (release version)
  4. In Apply:
    • check frontmatter preconditions first
    • return unchanged content and applied=false when migration is not needed
    • transform only frontmatter using applyFrontmatterLineTransform from pkg/cli/yaml_frontmatter_utils.go
    • preserve comments/formatting/markdown body
    • avoid lossy rewrites and avoid touching unrelated keys
  5. Prefer existing helpers before writing custom parsing logic:
    • findAndReplaceInLine
    • removeFieldFromBlock
    • removeParentBlockIfTrulyEmpty
    • newFieldRemovalCodemod
    • newMoveTopLevelKeyToOnBlockCodemod
  6. If the codemod depends on external data or side effects, inject dependencies through a ...WithDeps constructor so tests can mock behavior.
  7. Register the codemod in pkg/cli/fix_codemods.go within GetAllCodemods().

Testing requirements

Create pkg/cli/codemod_<feature>_test.go and cover:

  1. Metadata correctness (ID, Name, Description, IntroducedIn, Apply != nil).
  2. Happy path migration with expected output.
  3. No-op behavior when deprecated input is absent.
  4. Idempotence behavior (already-migrated input remains unchanged).
  5. Preservation guarantees:
    • inline comments
    • indentation
    • markdown body after frontmatter
  6. Edge cases specific to the codemod (nested fields, mixed forms, ordering constraints, strict-mode checks, etc.).
  7. Dependency-injection behavior if ...WithDeps exists (success and fallback/error paths).

When complexity is high (expression rewriting, parser-like behavior), add fuzz tests in codemod_<feature>_fuzz_test.go using the pattern in pkg/cli/codemod_steps_run_secrets_env_fuzz_test.go.

Registry/order tests

After adding a codemod, update pkg/cli/fix_codemods_test.go:

  1. Expected codemod IDs list.
  2. Expected codemod order list.

Order matters because codemods run sequentially and later codemods observe prior transformations.

Validation commands

Run targeted checks first:

  1. go test -v ./pkg/cli -run Codemod -count=1
  2. go test -v ./pkg/cli -run Fix -count=1

Then run repository standards:

  1. make build
  2. make test-unit
  3. make lint

Quality bar

A codemod is ready only when it is:

  • deterministic
  • safe on repeated runs
  • conservative (no unrelated rewrites)
  • fully covered by tests for migration and no-op paths
  • registered and order-verified in fix codemod registry tests

github의 다른 스킬

debugging-workflows
github
GitHub 에이전틱 워크플로우 디버깅 가이드 - 로그 분석, 실행 감사, 문제 해결
acreadiness-policy
github
사용자가 AgentRC 정책을 선택, 작성 또는 적용할 수 있도록 지원합니다. 정책은 관련 없는 검사를 비활성화하고, 영향/수준을 재정의하며, 설정을 통해 준비 상태 점수를 사용자 지정합니다.
ai-ready
github
어떤 저장소든 AI에 대비하도록 만듭니다 — 코드베이스를 분석하고 AGENTS.md, copilot-instructions.md, CI 워크플로우, 이슈 템플릿 등을 생성합니다. PR 리뷰를 분석합니다…
create-oo-component-documentation
github
객체 지향 컴포넌트에 대한 포괄적이고 표준화된 문서를 업계 모범 사례 및 아키텍처 문서 표준에 따라 생성합니다.
dependabot
github
Dependabot은 GitHub에 내장된 의존성 관리 도구로, 세 가지 핵심 기능을 제공합니다.
doublecheck
github
AI 출력을 위한 3계층 검증 파이프라인. 검증 가능한 주장을 추출하고, 웹 검색을 통해 지지하거나 반박하는 출처를 찾으며, 적대적 검토를 수행합니다…
foundry-agent-sync
github
Azure AI Foundry 내에서 REST API를 통해 로컬 JSON 매니페스트로부터 프롬프트 기반 AI 에이전트를 직접 생성하고 동기화합니다. 스캐폴딩 스킬과 달리 단순히...
gdpr-compliant
github
코드베이스 전반에 GDPR 준수 엔지니어링 관행을 적용하세요. API를 설계하거나, 데이터 모델을 작성하거나, 인증을 구축할 때마다 이 스킬을 사용하세요.