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

oxfmt

package
v1.65.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package oxfmt checks and formats JavaScript/TypeScript workspaces with Oxfmt using the shared @gv-tech/oxc-config style, without requiring a local install.

Bare invocations verify formatting (check mode); pass Options.Write to format files in place. Set Options.Diff to also render a colored unified-style diff of the pending changes.

Index

Constants

View Source
const (
	RunnerAuto  = "auto"
	RunnerNpx   = "npx"
	RunnerBun   = "bun"
	RunnerOxfmt = "oxfmt"
)

Runner selection values for Options.Runner.

View Source
const ConfigPackage = "@gv-tech/oxc-config@latest"

ConfigPackage is the shareable style package forwarded to the npx/bun wrapper.

View Source
const MaxDiffBytes = 1 << 20

MaxDiffBytes skips stdin formatting for files larger than this during --diff.

View Source
const MaxDiffFiles = 20

MaxDiffFiles caps how many per-file diffs check mode renders with Options.Diff.

Variables

View Source
var ErrUnformatted = errors.New("formatting check failed: files would be reformatted")

ErrUnformatted is returned when check mode finds files needing formatting. Callers use errors.Is to distinguish "dirty workspace" from hard failures.

Functions

func RenderDiff

func RenderDiff(path, oldText, newText string) string

RenderDiff returns a colored unified-style diff between oldText and newText for path. It returns an empty string when the inputs are identical.

func Run

func Run(ctx context.Context, opts Options, runner execx.Runner) error

Run checks or formats target with Oxfmt using the @gv-tech/oxc-config style.

Check mode (default) lists files that would change and returns ErrUnformatted when the workspace is dirty. Write mode formats in place.

Types

type LaunchSpec

type LaunchSpec struct {
	Binary string
	Args   []string
	Direct bool
}

LaunchSpec describes the binary plus leading args used to invoke oxfmt. Direct specs call a local oxfmt; wrapper specs go through the gv-oxfmt runner (npx --package ... / bun x --package ...) which bundles the @gv-tech/oxc-config style.

func ResolveLauncher

func ResolveLauncher(opts Options, lookPath func(string) (string, error), bunLockExists bool) (LaunchSpec, error)

ResolveLauncher picks the oxfmt entrypoint for opts.Runner.

Auto mode prefers the gv-oxfmt wrapper (bun, then npx) so the shared @gv-tech/oxc-config style applies even without a local install. A local oxfmt binary is only the last resort: it honors project config discovery (or ships defaults) rather than the shared style. With an explicit --config, a local oxfmt is preferred since no style package is needed.

Callers may inject lookPath and bunLockExists for testing; pass nil/false for production behavior (execx.LookPath plus a bun.lock ancestor search).

type Options

type Options struct {
	Path       string
	Write      bool
	Check      bool
	Diff       bool
	Runner     string
	ConfigPath string
	IsVerbose  bool
}

Options is the pure-data input for Run. The cmd layer adapts flags into it and never passes Viper/config values beyond plain fields.

func (*Options) Validate

func (o *Options) Validate() error

Validate rejects contradictory flag combinations and normalizes defaults.

Jump to

Keyboard shortcuts

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