lint

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package lint is the extensible content-pack lint surface. Consumers register `Linter` implementations against a `Registry`, then call `Run` to collect `Findings`. Severity-Error findings fail the `forge content lint` exit code and (when wired) the pack build.

Domain-specific lints live in the consumer (mmo-game registers "no reaction-window < 200ms", loot-table-sum > 0, ref-integrity, etc.); this kit owns the registry, severity routing, and runner.

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicateName = errors.New("lint: linter with that name already registered")

ErrDuplicateName is returned by Register when another linter with the same Name() is already installed.

Functions

This section is empty.

Types

type Finding

type Finding struct {
	Severity Severity
	Entry    string // pack-relative path, or "" for pack-wide
	Code     string // short stable identifier (used in CLI summaries)
	Message  string
}

Finding is one diagnostic produced by a Linter.

type Findings

type Findings []Finding

Findings is the result list. Methods give CLI runners helpful shortcuts.

func RunPackDir

func RunPackDir(ctx context.Context, dir string, r *Registry) (Findings, error)

RunPackDir loads the pack at dir and runs r against it. Convenience wrapper for the `forge content lint <dir>` CLI surface.

func (Findings) HasErrors

func (f Findings) HasErrors() bool

HasErrors reports whether any finding is of severity Error.

type Linter

type Linter interface {
	// Name is a stable identifier used in CLI summaries.
	Name() string
	// Lint is the actual check.
	Lint(ctx context.Context, pack *content.Pack) Findings
}

Linter checks one pack and returns Findings. Implementations should be pure — no I/O beyond reading the pack itself.

type LinterFunc

type LinterFunc struct {
	Named string
	Fn    func(ctx context.Context, pack *content.Pack) Findings
}

LinterFunc adapts a function (plus a name) to Linter.

func (LinterFunc) Lint

func (l LinterFunc) Lint(ctx context.Context, pack *content.Pack) Findings

Lint implements Linter.

func (LinterFunc) Name

func (l LinterFunc) Name() string

Name implements Linter.

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry composes multiple Linters.

func New

func New() *Registry

New constructs an empty Registry.

func (*Registry) MustRegister

func (r *Registry) MustRegister(l Linter)

MustRegister panics on error.

func (*Registry) Names

func (r *Registry) Names() []string

Names returns the registered linter names in registration order.

func (*Registry) Register

func (r *Registry) Register(l Linter) error

Register installs a Linter. Returns ErrDuplicateName if another linter with the same Name() is already registered.

func (*Registry) Run

func (r *Registry) Run(ctx context.Context, pack *content.Pack) Findings

Run executes every registered linter against pack and concatenates findings (stable-sorted by Entry then Code so output is reproducible across runs).

type Severity

type Severity uint8

Severity orders lint findings.

const (
	// Info — informational, never fails the build.
	Info Severity = iota
	// Warn — surfaced but doesn't fail.
	Warn
	// Error — fails the lint exit code and (when wired) the build.
	Error
)

func (Severity) String

func (s Severity) String() string

String returns the lower-case severity label used in CLI output.

Jump to

Keyboard shortcuts

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