fix

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fix applies mechanically safe remediations.

Only rules whose remediation is provably semantics-preserving get a fix. Everything else is explain-only, because a linter that silently changes meaning is worse than one that merely complains. QD002, for instance, has no fix: choosing between relaxing the label and separating the directories is a decision about what the user meant, not a mechanical transformation.

Two properties are load-bearing and are asserted by test:

  • Idempotence: applying a fix twice equals applying it once. Otherwise running the tool in CI would produce an endless diff.
  • Locality: bytes outside the region a fix touches are unchanged. This is why the parser retains the original text of every line.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(c Change) string

Diff renders a unified diff of a change, for previewing.

func Write

func Write(result *Result) error

Write applies the changes to disk.

Types

type Change

type Change struct {
	// Path is the file to change. For a file that does not exist yet, such as
	// the network unit QD030 creates, Created is true.
	Path    string
	Before  string
	After   string
	Created bool
	// Rules lists the rule IDs that contributed to this change.
	Rules []string
}

Change is one file's worth of proposed edit.

func (Change) Modified

func (c Change) Modified() bool

Modified reports whether the change actually alters anything.

type Options

type Options struct {
	// Only restricts fixing to these rule IDs. Empty means every fixable rule.
	Only map[string]bool
}

Options control which fixes are applied.

type Result

type Result struct {
	Changes []Change
	// Unfixed are findings whose rules have no mechanical fix, so the user
	// knows what is left to do by hand.
	Unfixed []rules.Finding
}

Result is everything a fix run proposes.

func Apply

func Apply(project *ir.Project, findings []rules.Finding, opts Options) (*Result, error)

Apply computes the changes that would resolve the given findings.

It returns the proposed content rather than writing it, so the caller can show a diff first. Writing is a separate, explicit step.

Jump to

Keyboard shortcuts

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