fix

package
v0.23.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Source added in v0.13.0

func Source(opts SourceOptions) ([]byte, error)

Source applies every fixable rule allowed by the effective config and returns the resulting bytes. The returned bytes equal the input when no rule produced an edit.

func SourceWithRules added in v0.13.0

func SourceWithRules(opts SourceOptions, names []string) ([]byte, error)

SourceWithRules is like Source but only the named rules are applied. An empty names slice produces no fixes.

Types

type Fixer

type Fixer struct {
	Config           *config.Config
	Rules            []rule.Rule
	StripFrontMatter bool
	Logger           *vlog.Logger
	// RootDir is the project root directory (parent of .mdsmith.yml).
	// Used by rules that need to read files relative to the project root.
	RootDir string
	// MaxInputBytes is the maximum file size in bytes before a file is
	// skipped with an error. Zero or negative means unlimited.
	MaxInputBytes int64
	// Explain, when true, attaches per-leaf rule provenance to each
	// remaining diagnostic so output formatters can render an
	// explanation trailer.
	Explain bool
	// SourceFS, when non-nil, overrides the per-file dirFS that
	// prepareFile would otherwise derive from filepath.Dir(path).
	// Used by Source / SourceWithRules so callers can pass a
	// workspace-relative path for config matching while still giving
	// include/catalog/cross-file rules a real filesystem rooted at
	// the document's actual directory. Disk-based Fix() (path-based)
	// leaves this nil and continues to derive dirFS from each file's
	// absolute path.
	SourceFS fs.FS
	// contains filtered or unexported fields
}

Fixer applies auto-fixes for fixable rules and reports remaining diagnostics.

func (*Fixer) Fix

func (f *Fixer) Fix(paths []string) *Result

Fix applies auto-fixes to the files at the given paths and returns a Result containing remaining diagnostics, modified file paths, and any errors.

type Result

type Result struct {
	// FilesChecked is the number of files processed (after ignore filtering).
	FilesChecked int
	// Failures is the number of diagnostics found before attempting fixes.
	Failures int
	// Diagnostics contains remaining diagnostics after fixing (from non-fixable
	// rules and any violations that could not be auto-fixed).
	Diagnostics []lint.Diagnostic
	// Modified lists file paths that were written back to disk.
	Modified []string
	// Errors contains any errors encountered during the fix process.
	Errors []error
}

Result holds the outcome of a fix run.

type SourceOptions added in v0.13.0

type SourceOptions struct {
	Config           *config.Config
	Rules            []rule.Rule
	Path             string
	Source           []byte
	RootDir          string
	StripFrontMatter bool
	// MaxInputBytes caps Source size before any fix runs. Semantics
	// match lint.ReadFileLimited: <= 0 or math.MaxInt64 means
	// unlimited; > 0 means reject buffers larger than that many
	// bytes. Callers that want the default 2 MB cap must pass
	// lint.DefaultMaxInputBytes explicitly.
	MaxInputBytes int64
	// SourceFS, when non-nil, is the filesystem the fixable rules
	// (include/catalog/cross-file) see for the buffer. Callers that
	// pass a workspace-relative Path (for config glob matching) MUST
	// also supply a SourceFS rooted at the document's real
	// directory; otherwise the dirFS derived from the relative path
	// would be resolved against the process CWD, breaking
	// neighbour-file lookups when the editor is launched from
	// elsewhere.
	SourceFS fs.FS
}

SourceOptions configures an in-memory fix run. The fix functions (Source, SourceWithRules) do not touch disk; they reuse the same prep/apply machinery the path-based Fixer uses on a buffer.

Jump to

Keyboard shortcuts

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