Documentation
¶
Overview ¶
Package engine applies a project's own formatters to a single file, safely.
The design rule that everything else follows from: a third-party tool is never given the user's file. Content is piped in on stdin and read back on stdout, the chain is evaluated as a pure function, and onwrite performs one atomic write at the end only if every formatter in the chain succeeded.
That single decision removes most of the ways a format-on-write tool can destroy data:
- A truncated, half-written file does not parse, so the formatter exits non-zero, so nothing is written and the original survives untouched.
- A formatter that crashes or is killed mid-run cannot leave a partial file behind, because it never held a file handle on one.
- A chain that fails at step three does not leave step two's output on disk, because nothing is on disk until the chain finishes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsTempName ¶
IsTempName reports whether a basename is one of onwrite's own scratch files.
Types ¶
type Config ¶
type Config struct {
// MaxSize is the largest file onwrite will format. Beyond this the cost
// stops being invisible and the file is almost certainly generated.
MaxSize int64
// Timeout bounds a single tool invocation.
Timeout time.Duration
// DryRun computes the formatted result but never writes.
DryRun bool
// Log receives progress.
Log Logger
}
Config tunes the engine.
type Engine ¶
type Engine struct {
Root string
Proj *detect.Project
Ign *scan.Ignorer
// contains filtered or unexported fields
}
Engine formats files for one project root.
type Logger ¶
type Logger interface {
Debugf(format string, args ...any)
Infof(format string, args ...any)
Errorf(format string, args ...any)
}
Logger receives human-readable progress. A nil Logger discards everything.
type Result ¶
type Result struct {
Path string
Changed bool
Skip Skip
Tools []string
Err error
Duration time.Duration
}
Result reports what happened to one file.
type Skip ¶
type Skip string
Skip explains why a file was not formatted. A skip is never an error; it is the normal outcome for most files onwrite is asked about.
const ( SkipNone Skip = "" SkipIgnored Skip = "ignored" SkipNoTool Skip = "no formatter for this file type" SkipTooLarge Skip = "file too large" SkipBinary Skip = "binary file" SkipSelfWrite Skip = "onwrite wrote this content" SkipNotFile Skip = "not a regular file" SkipSymlink Skip = "symlink" SkipEmpty Skip = "empty file" SkipUnstable Skip = "still being written" )
type TimeoutError ¶
TimeoutError is returned when a tool exceeds the per-invocation budget.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string