engine

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckRules

func CheckRules(f *lint.File, rules []rule.Rule, effective map[string]config.RuleCfg) ([]lint.Diagnostic, []error)

CheckRules runs all enabled rules against f, cloning and applying settings for Configurable rules. It adjusts diagnostics using f.AdjustDiagnostics and returns the collected diagnostics and any settings-application errors.

func ConfigureRule

func ConfigureRule(rl rule.Rule, cfg config.RuleCfg) (rule.Rule, error)

ConfigureRule clones a rule and applies settings from cfg if the rule implements Configurable and cfg has settings. Returns the configured rule (or the original if no settings apply) and any error from ApplySettings.

func DedupeDiagnostics added in v0.9.0

func DedupeDiagnostics(diags []lint.Diagnostic) []lint.Diagnostic

DedupeDiagnostics returns a new slice with duplicate (file, line, column, rule, message) tuples collapsed to a single entry. Repo- level rules (notably MDS048 git-hook-sync) emit a diagnostic anchored to the repository artifact for every linted file in the repo, so a fresh `mdsmith check` over a large tree would otherwise print the same warning N times and duplicate that entry in the returned diagnostics. Earlier-encountered duplicates win so the diagnostic order from the first hit is preserved. The input slice is never modified; nil input returns nil and a non-nil input always produces a freshly-allocated slice so callers can keep the original around without worrying about aliasing.

Types

type Result

type Result struct {
	// FilesChecked is the number of files processed (after ignore filtering).
	FilesChecked int
	Diagnostics  []lint.Diagnostic
	Errors       []error
}

Result holds the output of a lint run.

type Runner

type Runner 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
	// diagnostic so output formatters can render an explanation trailer.
	Explain bool
	// ConfigPath is the path to the loaded .mdsmith.yml. When set,
	// config-target rules (rule.ConfigTarget) are run once against a
	// synthetic lint.File for this path before per-file processing.
	ConfigPath string
	// contains filtered or unexported fields
}

Runner drives the linting pipeline: for each file it reads the content, builds a File (parsing the AST once), determines the effective rule configuration, runs enabled rules, and collects diagnostics.

func (*Runner) Run

func (r *Runner) Run(paths []string) *Result

Run lints the files at the given paths and returns a Result containing all diagnostics (sorted by file, line, column, message) and any errors encountered.

func (*Runner) RunSource

func (r *Runner) RunSource(path string, source []byte) *Result

RunSource lints in-memory source bytes (e.g. from stdin) and returns a Result. It creates a File via NewFileFromSource, determines the effective config, and uses CheckRules (which includes clone+settings logic and line-offset adjustment).

The File's FS field is left nil because in-memory source has no meaningful filesystem context. Rules that access f.FS must handle nil (include short-circuits when FS is nil). RootFS is set when RootDir is configured for potential future use, but currently has no effect on stdin since the include rule requires FS to be non-nil.

Jump to

Keyboard shortcuts

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