scan

package
v0.0.0-...-b9fa5af Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2025 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FrontMatter

type FrontMatter struct {
	Data           map[string]any
	Content        string
	HasFrontMatter bool
	SchemaSource   string         // "flag", "inline", "key", or "none"
	SchemaRef      string         // when SchemaSource == "key"
	InlineSchema   map[string]any // when SchemaSource == "inline"
}

FrontMatter contains parsed front matter data. We keep it generic as map[string]any so schemas can be flexible. Content is the remaining markdown without the front matter fence. SchemaSource indicates from where schema came (flag or inline or key reference) SchemaRef holds the path/URL when schema is referenced via key InlineSchema holds parsed inline schema object if present If neither is set and no global schema, no validation occurs.

func ParseFrontMatter

func ParseFrontMatter(content string) (*FrontMatter, error)

ParseFrontMatter extracts YAML front matter from markdown content. For now, we only support YAML front matter (between --- fences at the beginning of the file), as it's the most common; JSON can be added later.

func (*FrontMatter) DetermineSchemaType

func (fm *FrontMatter) DetermineSchemaType() SchemaType

DetermineSchemaType analyzes the front matter data to determine the schema type.

func (*FrontMatter) GetSchemaSource

func (fm *FrontMatter) GetSchemaSource() SchemaType

GetSchemaSource returns the schema source as a typed enum.

func (*FrontMatter) GetSchemaType

func (fm *FrontMatter) GetSchemaType() SchemaType

GetSchemaType returns the current schema type as a typed enum.

func (*FrontMatter) HasSchema

func (fm *FrontMatter) HasSchema() bool

HasSchema returns true if the front matter contains schema information.

func (*FrontMatter) SetSchemaType

func (fm *FrontMatter) SetSchemaType(schemaType SchemaType)

SetSchemaType sets the schema source using a typed enum.

type Options

type Options struct {
	Root       string
	Recursive  bool
	Extensions []string
	SchemaPath string // optional global schema path/URL
	Force      bool   // fail files without front matter when true
	// Workers allows overriding the number of concurrent workers used during scanning.
	// When 0 or negative, a default based on CPU count is used.
	Workers int
}

Options controls the behavior of the scanner.

type Result

type Result struct {
	Path   string
	Valid  bool
	Issues []string
}

Result represents a validation result for a single file.

func Scan

func Scan(ctx context.Context, opts Options) ([]Result, error)

Scan walks files under root according to options, parses front matter, and validates.

func ValidateContent

func ValidateContent(ctx context.Context, content, baseDir, schemaPath string, force bool) Result

ValidateContent validates markdown content directly without file system operations. SchemaPath, when provided, takes precedence over any $schema in the front matter. When no schema is available: if force is true and there's no front matter, the result fails; otherwise the result is OK with a "no schema provided" warning.

type SchemaType

type SchemaType string

SchemaType represents the source of schema configuration.

const (
	SchemaTypeFlag   SchemaType = "flag"
	SchemaTypeInline SchemaType = "inline"
	SchemaTypeKey    SchemaType = "key"
	SchemaTypeNone   SchemaType = "none"
)

func (SchemaType) IsValid

func (st SchemaType) IsValid() bool

IsValid returns true if the schema type is one of the known valid types.

Jump to

Keyboard shortcuts

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