singlelinefunclint

command
v1.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Command singlelinefunclint enforces the project's no-single-line-function rule (CODING_STYLE.md: "Never write single-line functions. Always spread function bodies across multiple lines, even for simple implementations.").

A function *declaration* violates the rule when its body has at least one statement and its opening and closing braces sit on the same source line. Empty bodies are exempt: there is nothing to spread.

Function *literals* (anonymous closures passed as arguments — predicate tables, comparators, field accessors) are deliberately NOT checked. The codebase uses one-line literals idiomatically and pervasively (e.g. `func(a, b rune) bool { return a < b }`); the rule, like the style guide's "spread function bodies" wording, targets declarations. Widening to literals would flag dozens of correct, deliberate call sites.

Same-line detection is a positional property the gocritic/ruleguard DSL cannot express (it matches AST shape, not brace lines), so this lives as a standalone go/ast pass, mirroring cmd/typeswitchlint.

It exits non-zero when any violation is found, so it can gate `make lint`.

Usage:

go run ./cmd/singlelinefunclint [dir...]

If no directories are given, it scans the current directory recursively. Test files (_test.go) are skipped, consistent with the ruleguard rules in ruleguard/rules.go that exempt tests from the production-only conventions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL