Documentation
¶
Overview ¶
Package convention computes per-package AST statistics that describe the package's prevailing idioms — error handling style, logging library, naming patterns, concurrency primitives. CKV exposes these raw stats so the agent (or a SKILL) can read what conventions a package follows before proposing edits.
CKV deliberately does no interpretation here: stats are numbers and counts. Summarization belongs to the agent's SKILL, where the LLM can phrase them in context-appropriate prose.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator accumulates per-file stats then resolves into a per-package map.
func NewAggregator ¶
func NewAggregator() *Aggregator
NewAggregator creates an empty accumulator. Safe to use without initialization via the zero value as long as ObservePackage is called before Result.
func (*Aggregator) ObserveFile ¶
func (a *Aggregator) ObserveFile(file string, src []byte) error
ObserveFile parses src and folds its stats into the aggregator. file is the repo-relative path (used to derive the package key as filepath.Dir and to detect *_test.go).
func (*Aggregator) Result ¶
func (a *Aggregator) Result() map[string]Stats
Result returns the per-package stats. Keys are package paths (filepath.Dir of the first observed file in that package). The map is fresh; subsequent ObserveFile calls do not mutate it.
type Stats ¶
type Stats struct {
// Errors counts the error-construction style:
// "fmt.Errorf_wrap" — fmt.Errorf with a %w verb
// "fmt.Errorf_plain" — fmt.Errorf without %w
// "errors.New" — errors.New
// "pkg/errors.Wrap" — github.com/pkg/errors.Wrap (legacy)
Errors map[string]int
// Loggers counts well-known logger call sites:
// "log15", "zap", "slog", "stdlib_log"
Loggers map[string]int
// Receivers counts struct receiver short-name length distribution.
// Keys are the short names ("s", "srv", "store", ...).
Receivers map[string]int
// NewConstructors counts the number of top-level `func New*` and
// `func MustNew*` constructors (idiom for builder vs zero-value).
NewConstructors int
// TestFiles counts *_test.go files in the package.
TestFiles int
// TableDriven counts `for _, tc := range cases` / `for _, tt`
// patterns — the conventional table-driven test idiom.
TableDriven int
// TestifyUses counts imports of stretchr/testify.
TestifyUses int
// Mutexes counts sync.Mutex / sync.RWMutex declarations.
Mutexes int
// Channels counts make(chan ...) call sites.
Channels int
// ErrGroupUses counts uses of golang.org/x/sync/errgroup.
ErrGroupUses int
// FileCount is the total number of files contributing to these
// stats; useful for normalizing other counters.
FileCount int
}
Stats is the per-package statistic bundle. The map shape uses `any` so adding a new metric in v2 does not break consumers (the agent's SKILL filters keys it understands and ignores the rest).