Documentation
¶
Overview ¶
Package format defines the formatter and linter ports applied to staged edit content before it is committed, together with configured-command exec adapters and in-memory fakes for downstream tests.
Per SPEC §3.5, formatting rewrites staged content and linting blocks the edit on failure: a non-nil Linter error means the staged content is rejected. Both ports are pure boundaries (interface-first, dependency inversion) so the edit pipeline never depends on a concrete tool.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdFormatter ¶
type CmdFormatter struct {
// Name is the executable to run (resolved via PATH).
Name string
// Args are the arguments passed to the executable.
Args []string
}
CmdFormatter is a Formatter backed by an external command. The command is invoked with src piped to stdin and its stdout taken as the formatted result; a non-zero exit is reported as an error including stderr.
type CmdLinter ¶
type CmdLinter struct {
// Name is the executable to run (resolved via PATH).
Name string
// Args are the arguments passed to the executable.
Args []string
}
CmdLinter is a Linter backed by an external command. The command is invoked with src piped to stdin; a zero exit means clean (nil), while a non-zero exit (or launch failure) is a blocking lint failure including stderr.
type FakeFormatter ¶
type FakeFormatter struct {
// FormatFunc, when non-nil, fully determines Format's behaviour.
FormatFunc func(ctx context.Context, src []byte) ([]byte, error)
}
FakeFormatter is an in-memory Formatter for tests. When FormatFunc is set it is invoked; otherwise Format behaves as the identity transform, returning src unchanged.
type FakeLinter ¶
type FakeLinter struct {
// LintFunc, when non-nil, fully determines Lint's behaviour.
LintFunc func(ctx context.Context, src []byte) error
// Err is returned by Lint when LintFunc is nil. nil means clean.
Err error
}
FakeLinter is an in-memory Linter for tests. When LintFunc is set it is invoked; otherwise Lint returns Err (nil by default, meaning clean).
type Formatter ¶
type Formatter interface {
// Format returns the formatted form of src. The returned slice may alias
// or replace src; callers should treat it as the new staged content.
Format(ctx context.Context, src []byte) ([]byte, error)
}
Formatter rewrites staged source content. Format returns the formatted bytes, or an error if the underlying tool fails; on error the staged content is left unchanged by the caller.
type Linter ¶
type Linter interface {
// Lint reports whether src passes the configured checks. nil = clean.
Lint(ctx context.Context, src []byte) error
}
Linter validates staged source content. A nil return means the content is clean and the edit may proceed; a non-nil return is a lint failure that blocks the edit.