spec

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const SpecFileName = ".fault-spec.yaml"

SpecFileName is the default spec file name.

Variables

View Source
var AnchorPattern = regexp.MustCompile(`spec:([A-Za-z][A-Za-z0-9_-]*-\d+)`)

AnchorPattern matches spec anchors in source code comments: spec:REQ-001

Functions

func GroupAnchorsByReqID

func GroupAnchorsByReqID(anchors []Anchor) map[string][]Anchor

GroupAnchorsByReqID groups anchors by their requirement ID.

Types

type Anchor

type Anchor struct {
	ReqID string // the requirement ID referenced (e.g. "REQ-001")
	File  string // file path relative to repo root
	Line  int    // 1-based line number
}

Anchor represents a spec anchor found in source code.

func ExtractAnchorsFromDir

func ExtractAnchorsFromDir(root string) ([]Anchor, error)

ExtractAnchorsFromDir walks a directory tree and extracts all spec anchors. It skips binary files, vendor dirs, node_modules, and .git.

func ExtractAnchorsFromFile

func ExtractAnchorsFromFile(path string) ([]Anchor, error)

ExtractAnchorsFromFile scans a single file for spec anchors.

type Requirement

type Requirement struct {
	ID          string   `yaml:"id" json:"id"`
	Description string   `yaml:"description" json:"description"`
	Priority    string   `yaml:"priority" json:"priority"`
	Status      string   `yaml:"status" json:"status"`
	Targets     []string `yaml:"targets" json:"targets"`
	Tags        []string `yaml:"tags" json:"tags"`
}

Requirement represents a single requirement in the spec.

type Spec

type Spec struct {
	Version      int           `yaml:"version" json:"version"`
	Title        string        `yaml:"title" json:"title"`
	Requirements []Requirement `yaml:"requirements" json:"requirements"`
}

Spec represents a parsed specification file.

func LoadSpec

func LoadSpec(path string) (*Spec, error)

LoadSpec reads and parses a spec file. It dispatches to the appropriate parser based on the file extension: .md/.markdown → Markdown, otherwise YAML.

func ParseMarkdownSpec added in v0.7.2

func ParseMarkdownSpec(data []byte) (*Spec, error)

ParseMarkdownSpec parses a Markdown document into a Spec.

The first H1 heading becomes the spec title. H2 headings become top-level requirements (SEC-1, SEC-2, ...). H3 headings become sub-requirements (SEC-1-1, SEC-1-2, ...). Each section's body text becomes the requirement description.

func ParseSpec

func ParseSpec(data []byte) (*Spec, error)

ParseSpec parses spec bytes, trying YAML first, then Markdown as a fallback.

func ParseYAMLSpec added in v0.7.2

func ParseYAMLSpec(data []byte) (*Spec, error)

ParseYAMLSpec parses spec YAML bytes into a Spec (YAML only, no fallback).

func (*Spec) RequirementByID

func (s *Spec) RequirementByID(id string) *Requirement

RequirementByID returns the requirement with the given ID, or nil.

func (*Spec) RequirementIDs

func (s *Spec) RequirementIDs() []string

RequirementIDs returns all requirement IDs in order.

func (*Spec) Validate

func (s *Spec) Validate() error

Validate checks the spec for structural errors.

Jump to

Keyboard shortcuts

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