engine

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package engine discovers files, runs rules in parallel, applies inline suppression, and applies fixes or renders diffs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyEdits

func ApplyEdits(src []byte, edits []rule.TextEdit) ([]byte, error)

ApplyEdits returns src with every edit applied. Edits must not overlap; they are applied last-to-first so earlier offsets stay valid during splicing.

func Format

func Format(doc *document.Document) []byte

Format applies the deterministic, idempotent whitespace pass: it collapses 3+ consecutive blank lines (outside fenced code) to one, ensures a single trailing newline, and applies the always-safe details-blank-line fix. Trailing-whitespace stripping is intentionally omitted (two trailing spaces are a markdown hard line break).

func UnifiedDiff

func UnifiedDiff(path string, before, after []byte) string

UnifiedDiff renders a unified diff of before vs after for one file.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine holds the resolved active rule set and config.

func New

func New(cfg *config.Config, reg *rule.Registry) (*Engine, error)

New resolves the active rules: built-ins filtered by enable/disable/default, plus compiled declarative rules from the config `custom:` block.

func (*Engine) Fix

func (e *Engine) Fix(ctx context.Context, paths []string, unsafe, dryRun bool) ([]string, error)

Fix lints, applies safe (and optionally unsafe) fixes per file, and either writes the files (dryRun=false) or returns them without writing. It returns the list of changed paths.

func (*Engine) MarkdownFiles

func (e *Engine) MarkdownFiles(paths []string) ([]string, error)

MarkdownFiles returns the discovered markdown file paths under paths.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, paths []string) (*Result, error)

Run lints every discovered file under paths and returns sorted findings.

type Result

type Result struct {
	Findings []rule.Finding
}

Result is the outcome of a Run.

func (*Result) ExitCode

func (r *Result) ExitCode() int

ExitCode is 1 when any Error-severity finding is present, else 0.

type Suppressor

type Suppressor struct {
	// contains filtered or unexported fields
}

Suppressor matches findings against inline doclint-disable directives and tracks which directives went unused.

func NewSuppressor

func NewSuppressor(doc *document.Document) *Suppressor

NewSuppressor scans a document for suppression directives.

func (*Suppressor) Suppressed

func (s *Suppressor) Suppressed(f rule.Finding) bool

Suppressed reports whether f is silenced, marking the matching directive used.

func (*Suppressor) Unused

func (s *Suppressor) Unused() []rule.Finding

Unused returns findings describing directives that matched nothing.

Jump to

Keyboard shortcuts

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