requiredstructure

package
v0.23.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PathPattern added in v0.14.0

type PathPattern struct {
	Kind    string
	Pattern string
}

PathPattern records a kind's `path-pattern:` constraint: the kind that declared it and the glob the workspace-relative path of every file in the kind must match. Populated by the config merge layer from KindBody.PathPattern.

type Rule

type Rule struct {
	Schema       string         // first source's file path (single-source convenience)
	InlineSchema *schema.Schema // first source's parsed inline schema
	Sources      []SchemaSource // ordered list of schema sources (canonical)
	Placeholders []string       // placeholder tokens to treat as opaque
	PathPatterns []PathPattern  // kind-level path-pattern entries
}

Rule checks that a document's heading structure matches a schema.

A rule instance carries an ordered list of schema sources (Sources) — one per layer (kind, override, or top-level rule entry) that declared a `schema:` (file) or `inline-schema:` (inline map). The rule loads each source at Check time and composes them via schema.Compose; a file resolving to multiple kinds therefore layers each kind's constraints rather than letting the last one win.

Schema and InlineSchema mirror the first source's parsed form when exactly one source is present. They support tests that drive the rule directly through ApplySettings with the legacy single-source keys; the kind-level loader still rejects configurations that set both keys on the same layer.

func (*Rule) ApplySettings

func (r *Rule) ApplySettings(settings map[string]any) error

ApplySettings implements rule.Configurable.

Three input shapes are accepted, all collapsed into Sources:

  • `schema-sources` (canonical, set by the merge layer): a list of {file: path} / {inline: map} entries in source order.
  • `schema` (legacy single-source): a file path; equivalent to a one-entry schema-sources list.
  • `inline-schema` (legacy single-source): a YAML map; equivalent to a one-entry inline schema-sources list.

When called via the merge layer the rule sees only schema-sources; the legacy keys are retained for tests and direct callers. Mixing `schema` and `inline-schema` in the same settings call is rejected as before — the merge layer only produces schema-sources, so the guard fires only on hand-authored configs.

func (*Rule) Category

func (r *Rule) Category() string

Category implements rule.Rule.

func (*Rule) Check

func (r *Rule) Check(f *lint.File) []lint.Diagnostic

Check implements rule.Rule.

func (*Rule) ComposedSchema added in v0.18.0

func (r *Rule) ComposedSchema(f *lint.File) (*schema.Schema, error)

ComposedSchema parses and composes every schema source the rule resolved for f and returns the composed schema, or nil when the rule has no schema source. Exposed for the `extract` subcommand, which projects the same composed schema MDS020 validates against; it reuses composedSchemaForFix so the two paths cannot drift.

func (*Rule) DefaultSettings

func (r *Rule) DefaultSettings() map[string]any

DefaultSettings implements rule.Configurable.

func (*Rule) Fix added in v0.14.0

func (r *Rule) Fix(f *lint.File) []byte

Fix implements rule.FixableRule. For single file-based schemas it rewrites body lines whose {field} template matches but whose value disagrees with the document's front matter (body-sync fix). For any configured inline schema (single-source or composed across kinds) that declares an `index:` block, Fix also emits the JSON side-output next to the source file. `mdsmith check` skips the write, preserving check's read-only contract (plan 143).

Fix swallows errors (composition and WriteIndex both). WriteIndex itself records any I/O failure in the package-level cache keyed by f.Path; the next Check reads that cache and surfaces the underlying error in place of the generic "missing / out of date" message, so users are not trapped in a fix loop without signal. Composition errors are similarly swallowed — they re-surface on the next Check pass through the same checkComposedSources path.

func (*Rule) ID

func (r *Rule) ID() string

ID implements rule.Rule.

func (*Rule) Name

func (r *Rule) Name() string

Name implements rule.Rule.

func (*Rule) SettingMergeMode added in v0.7.0

func (r *Rule) SettingMergeMode(key string) rule.MergeMode

SettingMergeMode implements rule.ListMerger.

func (*Rule) TranslateLayerSettings added in v0.17.1

func (r *Rule) TranslateLayerSettings(settings map[string]any) map[string]any

TranslateLayerSettings implements rule.SettingsTranslator. It collapses one config layer's user-facing `schema:` (file path) or `inline-schema:` (map) keys into a single-entry `schema-sources` list and strips the legacy keys. Because the rule declares `schema-sources` as MergeAppend, layers that pass through deep-merge then accumulate their sources instead of scalar-replacing the previous layer — which is what lets a file resolving to several kinds compose every kind's schema (plan 156).

Empty values (`schema: ""`, `inline-schema: {}`) are stripped without contributing a source, so the rule's own DefaultSettings `schema: ""` placeholder never pollutes the composed list. The input map is treated as read-only; a new map is returned only when a legacy key is present.

type SchemaSource added in v0.17.1

type SchemaSource struct {
	File   string
	Inline *schema.Schema
}

SchemaSource is one entry in the rule's schema-sources list. Either File or Inline is set, never both. Inline schemas are pre-parsed at ApplySettings time so a malformed schema surfaces as a config-load error rather than a per-file diagnostic at Check time. File sources stay as paths because the rule reads them through the lint.File's RootFS at Check time.

Jump to

Keyboard shortcuts

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