Help us shape the future of Go! Take the 2026 Go Developer Survey

fieldvalidator

package
v2.70.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const FixGuidance = `` /* 672-byte string literal not displayed */

FixGuidance is the remedy for an offense. The CLI prints it and WriteTodo embeds it in the generated TODO file header, so the guidance a developer reads is identical wherever they meet it.

Variables

This section is empty.

Functions

func Report

func Report(offenses []Offense, w io.Writer)

Report writes a human-readable summary of offenses to w.

func WriteTodo

func WriteTodo(path string, todo *TodoFile) error

WriteTodo writes todo to path as a YAML file with the standard header comment. The file is created or overwritten.

Types

type Offense

type Offense struct {
	// Callsite is the file path (relative to the scanned directory) where the
	// deprecated field was found.
	Callsite string `yaml:"callsite"`
	// DeprecatedField is the field name string that should be replaced.
	DeprecatedField string `yaml:"deprecated_field"` //nolint:tagliatelle
	// StandardField is the labkit fields constant to use instead.
	StandardField string `yaml:"standard_field"` //nolint:tagliatelle
}

Offense represents a single instance of a deprecated logging field being used in a source file. One offense is recorded per unique (callsite, deprecated_field) pair.

func Scan

func Scan(dir string) ([]Offense, error)

Scan walks all .go files under dir and returns deduplicated offenses for any logging field names that appear in fields.Deprecated.

type ParseWarningError

type ParseWarningError struct {
	Count int // number of files that failed to parse
	Total int // total number of Go files encountered
}

ParseWarningError is returned alongside offenses by Scan when some (but not all) Go files failed to parse. Callers can use errors.As to detect this and treat it as a non-fatal warning rather than a hard failure.

func (*ParseWarningError) Error

func (e *ParseWarningError) Error() string

type TodoFile

type TodoFile struct {
	Offenses []Offense `yaml:"offenses"`
}

TodoFile is the in-memory representation of .labkit_logging_todo.yml.

func MergeTodo

func MergeTodo(existing *TodoFile, newOffenses []Offense) *TodoFile

MergeTodo combines existing offenses in todo with new ones found by Scan, deduplicating by (callsite, deprecated_field). Returns a new TodoFile.

func ReadTodo

func ReadTodo(path string) (*TodoFile, error)

ReadTodo reads a .labkit_logging_todo.yml file from path. If the file does not exist a zero-value TodoFile is returned without error.

Jump to

Keyboard shortcuts

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