This skill should be used when the user asks about "gocyclo", "funlen", "cyclop", "nestif", "cognitive complexity", "refactor long function", "reduce nesting", "complexity reduction", or needs guidance on simplifying complex Go code. Provides patterns and techniques for reducing Go code complexity while preserving behavior.
Detects complexity issues in Go code (gocyclo, funlen, nestif) and provides specific refactoring patterns like guard clauses, function extraction, and lookup tables to reduce cognitive complexity while preserving exact behavior.
/plugin marketplace add dkoosis/cc-plugins/plugin install go-lintbrush@cc-pluginsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Patterns and techniques for reducing cognitive complexity in Go code while preserving exact behavior.
Complexity linters measure how hard code is to understand and maintain:
| Linter | Measures | Threshold |
|---|---|---|
| gocyclo | Cyclomatic complexity (decision points) | >15 warning, >20 error |
| funlen | Function length in lines | >60 lines |
| cyclop | Package-level complexity | varies |
| nestif | Nesting depth | >4 levels |
| maintidx | Maintainability index | <20 |
Boring, obvious code > clever, compact code
When refactoring:
Replace nested conditions with early returns.
func process(data *Data) error {
if data != nil {
if data.Valid() {
if data.Ready() {
return doWork(data)
}
}
}
return errors.New("cannot process")
}
func process(data *Data) error {
if data == nil {
return errors.New("nil data")
}
if !data.Valid() {
return errors.New("invalid data")
}
if !data.Ready() {
return errors.New("data not ready")
}
return doWork(data)
}
Impact: nestif 3→0, gocyclo reduced
Move switch case logic to dedicated handlers.
func handle(op string, ctx context.Context, req *Request) (*Response, error) {
switch op {
case "create":
// 20 lines of create logic
validate(req)
prepare(req)
result := create(ctx, req)
return result, nil
case "update":
// 15 lines of update logic
...
case "delete":
// 10 lines of delete logic
...
}
}
func handle(op string, ctx context.Context, req *Request) (*Response, error) {
switch op {
case "create":
return handleCreate(ctx, req)
case "update":
return handleUpdate(ctx, req)
case "delete":
return handleDelete(ctx, req)
default:
return nil, fmt.Errorf("unknown op: %s", op)
}
}
func handleCreate(ctx context.Context, req *Request) (*Response, error) {
// Focused, testable function
}
Impact: cyclop reduced, each handler independently testable
Keep loops simple, move complex logic to helpers.
func processAll(items []Item) error {
for _, item := range items {
// 30 lines of processing
if err := validate(item); err != nil {
log.Error(err)
continue
}
transformed := transform(item)
if err := save(transformed); err != nil {
return err
}
notify(transformed)
}
return nil
}
func processAll(items []Item) error {
for _, item := range items {
if err := processItem(item); err != nil {
return errors.Wrapf(err, "item %s", item.ID)
}
}
return nil
}
func processItem(item Item) error {
if err := validate(item); err != nil {
log.Error(err)
return nil // skip invalid items
}
transformed := transform(item)
if err := save(transformed); err != nil {
return err
}
notify(transformed)
return nil
}
Impact: Linear main loop, testable processing
Extract complex conditionals to named functions.
if (a && b) || (c && !d) || (e && f && !g) {
doSomething()
}
if shouldProcess(a, b, c, d, e, f, g) {
doSomething()
}
// shouldProcess returns true when the processing conditions are met.
// Returns true if:
// - Both a and b are set, OR
// - c is set and d is not, OR
// - e and f are set and g is not
func shouldProcess(a, b, c, d, e, f, g bool) bool {
return (a && b) || (c && !d) || (e && f && !g)
}
Impact: Main code readable, logic testable
Replace conditional chains with data structures.
func getConfig(format string, version int, env string) Config {
if format == "json" && version >= 2 && env == "prod" {
return prodJSONConfig
}
if format == "json" && version >= 2 && env == "dev" {
return devJSONConfig
}
if format == "xml" && env == "prod" {
return prodXMLConfig
}
// ... more conditions
return defaultConfig
}
type configKey struct {
format string
version int
env string
}
var configs = map[configKey]Config{
{"json", 2, "prod"}: prodJSONConfig,
{"json", 2, "dev"}: devJSONConfig,
{"xml", 0, "prod"}: prodXMLConfig,
}
func getConfig(format string, version int, env string) Config {
if cfg, ok := configs[configKey{format, version, env}]; ok {
return cfg
}
return defaultConfig
}
Impact: Data-driven, trivially testable, easy to extend
One function should do one thing.
func LoadAndProcess(path string) (*Result, error) {
// Read file
data, err := os.ReadFile(path)
if err != nil { return nil, err }
// Parse
var config Config
if err := json.Unmarshal(data, &config); err != nil {
return nil, err
}
// Validate
if config.Name == "" { return nil, errors.New("missing name") }
if config.Port < 0 { return nil, errors.New("invalid port") }
// Transform
result := &Result{...}
// 20 lines of transformation
return result, nil
}
func LoadAndProcess(path string) (*Result, error) {
config, err := loadConfig(path)
if err != nil { return nil, err }
if err := validateConfig(config); err != nil {
return nil, err
}
return transformConfig(config), nil
}
func loadConfig(path string) (*Config, error) { ... }
func validateConfig(c *Config) error { ... }
func transformConfig(c *Config) *Result { ... }
Impact: Each function single-purpose, testable
When extracting helpers:
validateUserInput not validate| Level | Complexity Reduction | Helpers | Nesting |
|---|---|---|---|
| Good | ≥30% | 2-5 | Reduced |
| Excellent | ≥50% | Each <20 lines | Zero in main fn |
After refactoring:
# Tests must pass
go test -race ./...
# Lints must be clean
golangci-lint run --enable gocyclo,funlen,nestif ./...
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists' work to avoid copyright violations.
Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.
Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.