repolint

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package audit is abcd's read-only repo-conformance engine: it evaluates a set of declarative rules against a repository and returns findings. It performs no I/O beyond reading under a caller-supplied working directory — no printing, no os.Exit, no mutation — so it is fully testable and reusable across surfaces.

The design adapts three external patterns behind seams, copying vocabulary not code (see .abcd/development/plans/2026-07-13-abcd-audit-verb.md): repolinter's rule-object schema (id/severity/where/fix/policyInfo), Conftest's severity-to-exit-code semantics (0 clean, 1 warnings, 2 any error), and SARIF as a future optional export behind the Serializer seam. Net new dependencies: zero.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaxScanBytesForTest

func MaxScanBytesForTest() int

MaxScanBytesForTest exposes the scan cap to the package's external tests.

Types

type Context

type Context struct {
	// RepoRoot is the absolute path to the repository being audited.
	RepoRoot string
}

Context is what every rule is evaluated against: the repository under audit. It is passed by value; a rule must not mutate it.

type Finding

type Finding struct {
	RuleID   string   `json:"ruleId"`
	Severity Severity `json:"severity"`
	File     string   `json:"file,omitempty"`
	Line     int      `json:"line,omitempty"`
	Message  string   `json:"message"`
	Fix      string   `json:"fix,omitempty"`
	Policy   string   `json:"policyInfo,omitempty"`
}

Finding is one conformance violation. File is repo-relative; Line is 1-based (0 when the finding is not tied to a specific line, e.g. a missing directory). Fix and Policy are copied from the rule's Meta so a serialized finding is self-describing.

type JSONSerializer

type JSONSerializer struct{}

JSONSerializer emits abcd's native compact-but-indented JSON with stable rule ids. The top-level shape is { "findings": [...] } — always a present array, never null, so a clean repo emits { "findings": [] } exactly.

func (JSONSerializer) Serialize

func (JSONSerializer) Serialize(res Result) ([]byte, error)

type Result

type Result struct {
	Findings []Finding `json:"findings"`
	Skipped  []string  `json:"skipped"`
	Blockers int       `json:"-"`
	Warnings int       `json:"-"`
	ExitCode int       `json:"-"`
}

Result is the outcome of an audit. Findings are sorted deterministically. Blockers and Warnings count error- and warn-severity findings; ExitCode is the Conftest tri-state derived from them. Skipped names the rules whose Where predicate was false, so a caller can show "skipped (not applicable)" rather than silently omitting them.

func Evaluate

func Evaluate(rules []Rule, ctx Context) (Result, error)

Evaluate runs every rule against ctx and returns the aggregated, sorted result. A rule with SeverityOff is skipped without evaluation. A rule whose Where predicate is false is recorded in Skipped and not evaluated. If any rule's Eval returns an error, Evaluate aborts and returns it — a check that cannot run must not be silently reported as passing.

type Rule

type Rule interface {
	Meta() RuleMeta
	Where(ctx Context) bool
	Eval(ctx Context) ([]Finding, error)
}

Rule is one conformance check. Meta is its declarative header; Where gates conditional enablement (a false Where skips the rule rather than failing it — e.g. docs-currency when docs/ is absent); Eval runs the check and returns findings. Eval returns an error only when the check itself cannot run (a malformed input), never to signal a violation — a violation is a Finding. This interface is the rule-loader seam: rules are values the evaluator ranges over, not branches wired into it.

func DefaultRules

func DefaultRules() []Rule

DefaultRules returns the bundled, in-binary v1 rule set in a stable order. Rules are data the evaluator ranges over (the rule-loader seam), so a later phase can add repo-level overrides without touching Evaluate.

type RuleMeta

type RuleMeta struct {
	ID         string
	Severity   Severity
	Fix        string
	PolicyInfo string
}

RuleMeta is a rule's declarative header — data, separate from the evaluator. It mirrors repolinter's rule object: a stable ID (the machine key), a Severity, a Fix (the remediation message shown to a human), and PolicyInfo (why the rule exists).

type Serializer

type Serializer interface {
	Serialize(res Result) ([]byte, error)
}

Serializer turns a Result into bytes for a machine consumer. It is the output-serializer seam: the JSON serializer ships now; a SARIF serializer is a later, additive implementation of the same interface (itd-85 P3), not a change to the engine.

type Severity

type Severity string

Severity is a rule's weight. The vocabulary is repolinter/Conftest's error|warn|off, chosen over the record-lint engine's blocker|warn because it maps directly onto the tri-state exit code and reads correctly in the human render. A reused docs-lint finding (blocker|warn) is mapped at that rule's boundary, not here.

const (
	SeverityError Severity = "error"
	SeverityWarn  Severity = "warn"
	SeverityOff   Severity = "off"
)

Jump to

Keyboard shortcuts

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