format

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: MIT Imports: 4 Imported by: 0

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.

func (CmdFormatter) Format

func (f CmdFormatter) Format(ctx context.Context, src []byte) ([]byte, error)

Format runs the configured command with src on stdin and returns its stdout. A non-zero exit, or any failure to launch the command, yields an error wrapping the command name and the captured 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.

func (CmdLinter) Lint

func (l CmdLinter) Lint(ctx context.Context, src []byte) error

Lint runs the configured command with src on stdin. It returns nil when the command exits zero, and an error wrapping the command name and captured stderr otherwise.

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.

func (FakeFormatter) Format

func (f FakeFormatter) Format(ctx context.Context, src []byte) ([]byte, error)

Format delegates to FormatFunc when set, and otherwise returns src unchanged (identity formatting).

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).

func (FakeLinter) Lint

func (l FakeLinter) Lint(ctx context.Context, src []byte) error

Lint delegates to LintFunc when set, and otherwise returns Err.

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.

Jump to

Keyboard shortcuts

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