apishape
Checks exported API parameter and receiver shape.
What it detects
Reports exported functions with too many parameters, long runs of parameters that share one type, and adjacent optional scalar parameters that are easy to swap. It also reports types that mix pointer and value receiver methods.
Checks
| Check | What it detects |
|---|---|
parameter-count* |
Reports exported APIs with more than the configured maximum number of parameters. |
mixed-receivers* |
Reports types that mix pointer and value receiver methods. |
adjacent-same-type* |
Reports long adjacent runs of parameters that share one type. |
adjacent-optional-scalars* |
Reports adjacent optional scalar parameters that are easy to swap. |
* Opt-in; requires explicit selection.
Why this is flagged
Long parameter lists are difficult to read at call sites, and adjacent values of the same type can be swapped without the compiler noticing. Grouping related values in a named type makes each argument’s meaning explicit and makes the API safer to change later.
How to fix it
Put related parameters into a small, clearly named options or request type. When two adjacent values could be confused, give them distinct named types or group them into a type whose field names explain their purpose.
Examples
Flagged code
Too many parameters
// gohawk: exported API has 5 parameters; use an Input or config structfunc CreateUser(name string, age int, active bool, score float64, role byte) error { return nil}Adjacent optional parameters
// gohawk: adjacent optional scalar parameters are easy to swap; use an Input structfunc FindUser(firstName, lastName *string) error { return nil}Accepted code
type CreateUserInput struct { Name, Email, City, Country, Role string}
func CreateUserWithInput(input CreateUserInput) error { return nil}Options
| Knob | Default | Effect |
|---|---|---|
max-adjacent-same-type |
2 |
Maximum adjacent parameters of one type; 0 disables the check. |
max-parameters |
4 |
Maximum exported function parameters; 0 disables the check. |