A Go CLI tool that reformats function signatures exceeding a configurable line length. All other code is left byte-for-byte identical.
go install github.com/feedr-aps/sigfmt@latestsigfmt [flags] [paths...]
| Flag | Description | Default |
|---|---|---|
-w |
Write result to source file | off |
-l |
List files that would be changed | off |
-max-len |
Maximum line length | 100 |
-tab-width |
Tab display width for measurement | 4 |
# Check which files would change
sigfmt -l ./...
# Reformat in place
sigfmt -w ./...
# Print reformatted output to stdout
sigfmt path/to/file.go
# Read from stdin
cat file.go | sigfmt
# Custom line length
sigfmt -w -max-len 120 ./...-l exits with code 1 if any files would change, making it suitable for CI checks. -w and -l can be combined to list files as they are written.
Signatures that exceed the max line length are expanded — each parameter goes on its own line with a trailing comma:
// Before:
func (s *Server) HandleRequest(ctx context.Context, req *http.Request, logger *slog.Logger, opts ...Option) (Response, error) {
// After:
func (s *Server) HandleRequest(
ctx context.Context,
req *http.Request,
logger *slog.Logger,
opts ...Option,
) (Response, error) {Multi-line signatures that fit on one line are collapsed back:
// Before:
func Short(
a int,
b int,
) error {
// After:
func Short(a int, b int) error {Grouped parameters are expanded when splitting:
// Before:
func foo(a, b int, c string) ...
// After (when expanded):
func foo(
a int,
b int,
c string,
) ...Generic functions are supported. When type parameters are multi-line, the parameter line length is measured independently from the closing ](:
func ToMiddleware[
TFunc func(ctx context.Context) error,
](fn TFunc) Middleware {- Generated files (
// Code generated ... DO NOT EDIT.) - Files matched by
.gitignore vendor/,testdata/, and hidden directories- Signatures containing comments within the signature span (left untouched to avoid losing comments)
- Function literals (closures)
- Interface method declarations
- Return types are never split — only parameters are expanded
Only top-level *ast.FuncDecl nodes are processed. The tool uses go/ast to parse signatures and byte offsets to surgically replace only the signature spans in the original source, so formatting of all non-signature code is preserved exactly.