xiaohongshu
xiaohongshu
control-flow-check
Audits Go code for control flow excellence - early returns, minimal nesting, small blocks. Checks for happy path readability, guard clauses, and refactoring opportunities. Use before committing Go code or during refactoring.
Full skill instructions
Audit Go code for control flow best practices based on RMS Go coding standards. This skill identifies control flow anti-patterns and suggests refactoring opportunities to improve readability and maintainability.
Golden Rule: Use early returns for error cases and edge conditions to keep the happy path at the lowest indentation level.
Good Pattern:
func ProcessTask(task *Task) error {
if task == nil {
return errors.New("task is nil")
}
if !task.IsValid() {
return errors.New("invalid task")
}
// Happy path at lowest indentation
result := task.Execute()
return result.Save()
}
Bad Pattern:
func ProcessTask(task *Task) error {
if task != nil {
if task.IsValid() {
// Happy path nested 2 levels
result := task.Execute()
return result.Save()
} else {
return errors.New("invalid task")
}
} else {
return errors.New("task is nil")
}
}
Golden Rule: Maximum 2-3 levels of nesting. Deeper nesting indicates need for refactoring.
Detection Pattern:
{ in nested structuresGolden Rule: If/else blocks should be < 10 lines. Large blocks need extraction.
Detection Pattern:
if { and closing }else { and closing }Golden Rule: Validate inputs and preconditions at function start with early returns.
Good Pattern:
func UpdateTask(ctx rms.Ctx, taskID string, updates map[string]interface{}) error {
// Guard clauses at top
if taskID == "" {
return errors.New("taskID required")
}
if len(updates) == 0 {
return errors.New("no updates provided")
}
// Main logic after guards
task, err := fetchTask(ctx, taskID)
// ...
}
Guidance: Prefer early returns over else statements when possible.
Refactoring Pattern:
// Before
func IsValid(x int) bool {
if x > 0 {
return true
} else {
return false
}
}
// After
func IsValid(x int) bool {
if x > 0 {
return true
}
return false
}
# Find all Go files in the repository
find . -name "*.go" -not -path "*/vendor/*" -not -path "*/mock*" -not -path "*_test.go"
Use the Read tool to examine Go files, focusing on:
For each function, check:
A. Early Return Pattern
B. Nesting Depth
C. Block Size
D. Guard Clauses
E. Unnecessary Else
Create a structured report:
## Control Flow Audit: [file_path]
### ✅ Functions Following Best Practices
- `FunctionName` ([file:line]) - Early returns, minimal nesting
### ⚠️ Issues Found
#### HIGH Priority: Excessive Nesting
- **Function**: `ComplexFunction` ([file:line])
- **Issue**: Nesting depth of 4 levels at line X
- **Location**: Lines X-Y
- **Suggestion**: Extract nested logic into `helperFunction`
#### HIGH Priority: Missing Early Returns
- **Function**: `ProcessData` ([file:line])
- **Issue**: Happy path nested 2 levels, error checks not using early returns
- **Location**: Lines X-Y
- **Suggestion**: Add guard clauses at function start
#### MEDIUM Priority: Large Block
- **Function**: `HandleRequest` ([file:line])
- **Issue**: If block spans 15 lines (lines X-Y)
- **Suggestion**: Extract to `validateAndProcess` helper
#### LOW Priority: Unnecessary Else
- **Function**: `IsAuthorized` ([file:line])
- **Issue**: Else after return at line X
- **Suggestion**: Remove else, de-indent remaining code
For each issue found, provide:
## Summary
- Files checked: X
- Functions analyzed: Y
- Issues found: Z
- HIGH priority: A
- MEDIUM priority: B
- LOW priority: C
- Clean functions: W
This skill is invoked by:
quality-check skill for Go projectssafe-commit skill (via quality-check)# Manual invocation
/skill control-flow-check
# Automatic invocation via quality-check
/skill quality-check # Detects Go project, invokes control-flow-check
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience