lint

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

README

pkg/lint

Specification linting engine with pluggable rules. Validates spec trees for structural conventions.

Outstanding Questions

None at this time.

Documentation

Overview

specscore:feature/cli/spec/lint

Implements the `index-entries` rule and its --fix support. The bidirectional check (phantom links + orphan children) satisfies REQ:index-entries-bidirectional. The fixer satisfies REQ:index-entries-fix-deletes-phantom-rows (Phase 1) and REQ:index-entries-fix-inserts-orphan-rows (Phase 2). All three REQs and their ACs live under the "Features index synchronization" subsection of the cli/spec/lint feature README.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllRuleNames

func AllRuleNames() map[string]bool

AllRuleNames returns the canonical set of known rule names.

func RegisterChecker

func RegisterChecker(c Checker)

RegisterChecker registers a custom checker that will run alongside built-in checkers during Lint(). Must be called before any concurrent use of Lint (typically during init or program startup).

func RenderStudioToolbar

func RenderStudioToolbar(name, urlStr, host, org, repo, artifactPath string) string

RenderStudioToolbar returns the canonical toolbar line per studio-toolbar#req:toolbar-line-shape. The returned string includes the trailing LF. Callers (lint, --fix) compare or replace line 3 with this exact byte sequence.

Inputs:

  • name: studio.name (with or without dots; bold-wrap rules apply per brand-attribution-rendering / brand-attribution-no-dot / brand-attribution-multi-dot).
  • url: studio.url; MUST end in exactly one "/" — the validation is enforced upstream in projectdef.Validate(). The renderer strips the trailing "/" per url-grammar-trailing-slash before joining with the path grammar.
  • host, org, repo: resolved from specscore.yaml project.host/.org/.repo, falling back to git origin parsing.
  • artifactPath: the feature directory path from repo root, e.g. "spec/features/repo-config". MUST NOT include "/README.md".

func ResetCustomCheckers

func ResetCustomCheckers()

ResetCustomCheckers clears all registered custom checkers (for testing).

func ValidateRuleNames

func ValidateRuleNames(names []string) error

ValidateRuleNames checks that all names are known rules. The legacy `view-link` rule was removed by the studio-toolbar Feature; flagging it surfaces a migration message naming `studio-toolbar` as the replacement (studio-toolbar#req:studio-toolbar-lint-removes-view-link).

Types

type Checker

type Checker interface {
	Name() string
	Severity() string
	Check(specRoot string) ([]Violation, error)
}

Checker is the public interface for custom rule implementations. External tools can implement this to add custom rules to the linter.

type Options

type Options struct {
	SpecRoot string
	Rules    []string // enabled rules; nil = all
	Ignore   []string // disabled rules
	Severity string   // minimum severity: error, warning, info
	Fix      bool     // when true, auto-fixable violations are repaired on disk by checkers that support it
	// CLIVersion is the running CLI's own version as a semver string (e.g.
	// "0.3.0", with optional leading "v"). Used by the dogfood-version-bump
	// rule to detect stale pins in .github/workflows/*.yml. Empty, "dev",
	// or any non-semver value disables the comparison silently.
	CLIVersion string
}

Options holds linting options.

type Violation

type Violation struct {
	File     string `json:"file" yaml:"file"`
	Line     int    `json:"line" yaml:"line"`
	Severity string `json:"severity" yaml:"severity"`
	Rule     string `json:"rule" yaml:"rule"`
	Message  string `json:"message" yaml:"message"`
}

Violation represents a single linting violation.

func CheckIdeas

func CheckIdeas(specRoot string, fix bool) ([]Violation, error)

CheckIdeas runs all idea lint rules. If fix is true, auto-fixable violations are repaired on disk and omitted from the returned slice.

func FilterBySeverity

func FilterBySeverity(violations []Violation, minSeverity string) []Violation

FilterBySeverity filters violations to those at or above the minimum severity.

func Lint

func Lint(opts Options) ([]Violation, error)

Lint runs all enabled lint rules against the spec tree.

Jump to

Keyboard shortcuts

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