Documentation
¶
Overview ¶
Package engine discovers files, runs rules in parallel, applies inline suppression, and applies fixes or renders diffs.
Index ¶
- func ApplyEdits(src []byte, edits []rule.TextEdit) ([]byte, error)
- func Format(doc *document.Document) []byte
- func FormatWith(doc *document.Document, reg *FormatRegistry) []byte
- func UnifiedDiff(path string, before, after []byte) string
- type Engine
- func (e *Engine) Fix(ctx context.Context, paths []string, unsafe, dryRun bool) ([]string, error)
- func (e *Engine) MarkdownFiles(paths []string) ([]string, error)
- func (e *Engine) Restrict(names []string) error
- func (e *Engine) Run(ctx context.Context, paths []string) (*Result, error)
- func (e *Engine) UseCache(c *cache.Cache, version, configHash string)
- type FormatPass
- type FormatRegistry
- type Result
- type ShortcodeIndentPass
- type Suppressor
- type TableAlignPass
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplyEdits ¶
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 ¶
Format applies the full deterministic, idempotent formatting pass using the built-in default registry. See FormatWith for details on the individual steps.
func FormatWith ¶ added in v0.7.0
func FormatWith(doc *document.Document, reg *FormatRegistry) []byte
FormatWith runs the core formatting steps followed by every pass in reg. The core steps are:
- Apply always-safe structural fixes (blank lines around fences/lists/ headings, ATX-heading space, details blank line, trailing spaces).
- Collapse consecutive blank lines outside fenced code to at most one.
- Ensure a single trailing newline.
Registered passes then run in order, each receiving the previous pass's output. Built-in passes (registered by DefaultFormatRegistry) add:
- table-align — aligns GFM table column widths
- shortcode-indent — re-indents Hugo shortcode tag lines by nesting depth
Every step is idempotent; the structural fixes include no-trailing-spaces' targeted strip of a single stray trailing space or whitespace-only line — a deliberate two-space hard line break is never touched and an ambiguous 3+ run is left for a human.
func UnifiedDiff ¶
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 ¶
New resolves the active rules: built-ins filtered by enable/disable/default, plus compiled declarative rules from the config `custom:` block.
func (*Engine) Fix ¶
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 ¶
MarkdownFiles returns the discovered markdown file paths under paths.
func (*Engine) Restrict ¶ added in v0.5.0
Restrict limits the active rules to those named, so `lint --rule X` reports or fixes only X. It errors on a name that is not an active rule (unknown, or disabled by config). Custom rule ids are matched too.
type FormatPass ¶ added in v0.7.0
type FormatPass interface {
// Name returns the unique identifier for this pass, used in diagnostics.
Name() string
// Apply transforms src and returns the result.
Apply(src []byte) []byte
}
FormatPass is a single idempotent byte-level formatting pass. Passes run after the core formatter (structural fixes, blank-run collapse, trailing-newline normalisation) in registration order; each pass receives the output of the previous one.
Implementations must be idempotent: Apply(Apply(src)) == Apply(src). src is always valid UTF-8 markdown ending with exactly one trailing newline.
type FormatRegistry ¶ added in v0.7.0
type FormatRegistry struct {
// contains filtered or unexported fields
}
FormatRegistry holds the ordered sequence of FormatPass implementations applied after the core formatter. Register passes in the order you want them to run; each pass sees the previous pass's output.
func DefaultFormatRegistry ¶ added in v0.7.0
func DefaultFormatRegistry() *FormatRegistry
DefaultFormatRegistry returns a FormatRegistry pre-loaded with the built-in passes in their canonical order:
- table-align — aligns GFM table column widths
- shortcode-indent — re-indents Hugo shortcode tag lines by nesting depth
To add a new built-in pass, implement FormatPass in its own file and add a Register call here. To use a custom set, start with NewFormatRegistry.
func FormatRegistryFor ¶ added in v0.7.5
func FormatRegistryFor(cfg *config.Config) *FormatRegistry
FormatRegistryFor builds the format registry honoring cfg's `fmt` options: table-align always runs; shortcode-indent runs only when enabled, using the configured indent width and per-shortcode exclude list. A nil cfg yields the default registry.
func NewFormatRegistry ¶ added in v0.7.0
func NewFormatRegistry() *FormatRegistry
NewFormatRegistry returns an empty registry.
func (*FormatRegistry) All ¶ added in v0.7.0
func (r *FormatRegistry) All() []FormatPass
All returns the registered passes in registration order.
func (*FormatRegistry) Register ¶ added in v0.7.0
func (r *FormatRegistry) Register(p FormatPass)
Register appends a pass. Panics on duplicate names (programmer error).
type ShortcodeIndentPass ¶ added in v0.7.0
ShortcodeIndentPass is a FormatPass that fixes shortcode indentation inside list items. Standalone shortcodes are emitted verbatim (no tree indentation).
IndentWidth is the number of spaces added per shortcode nesting level inside a list-inline block (0 → the default of 2). Exclude names shortcodes whose whole subtree (opener through matching closer) is emitted verbatim — useful for shortcodes with carefully hand-aligned internals (e.g. uplatnica payment forms).
func (ShortcodeIndentPass) Apply ¶ added in v0.7.0
func (p ShortcodeIndentPass) Apply(src []byte) []byte
func (ShortcodeIndentPass) Name ¶ added in v0.7.0
func (ShortcodeIndentPass) Name() string
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.
type TableAlignPass ¶ added in v0.7.0
type TableAlignPass struct{}
TableAlignPass is a FormatPass that aligns the column widths of well-formed GFM tables. Malformed tables (row cell-count mismatch) are left untouched.
func (TableAlignPass) Apply ¶ added in v0.7.0
func (TableAlignPass) Apply(src []byte) []byte
func (TableAlignPass) Name ¶ added in v0.7.0
func (TableAlignPass) Name() string