repo

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: AGPL-3.0 Imports: 23 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 repo discovers, parses and relates the documents of a spec repository. Nothing here reads stdin, prompts, or exits.

Index

Constants

View Source
const (
	OpenQuestions     = "Open questions"
	ResolvedQuestions = "Resolved questions"
)

The question sections. A question is a level three heading in one, and a question in Resolved questions ends on a blockquote holding its answer, so an answered question is kept rather than deleted.

View Source
const Changelog = "Changelog"

Changelog is the section recording the edits made to a document while it is proposed, one list item per entry.

View Source
const DateLayout = "2006-01-02"

DateLayout is the ISO 8601 date form every date field uses.

View Source
const GlossaryPage = "glossary"

GlossaryPage is the spec page name the glossary always has.

View Source
const MaxBody = 131072

MaxBody is the length in bytes past which a body is not read. goldmark reads some shapes in time growing with the square of their length, and at this length the slowest of them takes about half a second.

View Source
const RejectionRationale = "Rejection rationale"

RejectionRationale is the section a rejected document gains, and which no other document may carry.

View Source
const Sources = "Sources"

Sources names what a document was checked or reconstructed against. Required on every ref, and on any backfilled document.

Variables

Statuses is every valid status.

Types is every document type, in directory order.

View Source
var WikiLinkPattern = wikiLinkPattern

WikiLinkPattern matches a [[...]] link, its name the first group.

Functions

func Anchor

func Anchor(text string) string

Anchor is the fragment GitHub would generate for a heading standing on its own. Headings inside a document take their anchors from a walk that numbers repeats, so this is only for naming the anchor a heading would have had when the heading is not there to ask.

func AnchorsIn

func AnchorsIn(source []byte) []string

AnchorsIn returns the heading anchors of arbitrary markdown, for checking a link into a file that is not itself a document, or nil where its body is longer than MaxBody and is not read.

func Contains

func Contains(root, full string) error

Contains reports whether full sits inside root once every directory component has been resolved.

config.ValidateRoot already checks the root itself, and that is not enough: a root can be perfectly ordinary while a document directory inside it points elsewhere, and every write into that directory then lands outside the repository while the tool reports a path inside it.

func EscapeMarkdown

func EscapeMarkdown(text string) string

EscapeMarkdown makes arbitrary text safe to place inside generated markdown: a table cell, or a link label. A title is free text, and a document called "Pwned](https://evil.example) x" would otherwise become a live hyperlink in another document's body and in the index, with lint reporting nothing.

The backslash goes first, or escaping the others would double it.

func FrontMatterParses added in v0.5.0

func FrontMatterParses(source []byte) bool

frontMatterParses reports whether a document's YAML block still reads. It asks only whether the structure is intact, not whether the fields are valid: a document with a bad date is lint's business, not a reason to refuse an unrelated edit. FrontMatterParses reports whether source still carries front matter that parses. SetField checks it after every rewrite, and so do its tests: a rewrite that produced something unreadable would otherwise reach disk and be noticed only by the next command to open the file.

func HeadingSurvives

func HeadingSurvives(text string) bool

HeadingSurvives reports whether text written as a heading reads back as itself. A trailing hash is a closing sequence and trailing whitespace is discarded, so a title carrying either produces an H1 that no longer matches the front matter, and a glossary term that can never be found by the name that was typed.

func Identifier

func Identifier(t Type, number int) string

Identifier renders the identifier for a type and number, as RFC-0001.

func ImplementedIn

func ImplementedIn(includedIn []string) []string

ImplementedIn is the spec pages whose inclusion of a document means the document has been built, which is every page but a spec/glossary.md left from before terms were files.

The full IncludedIn list is kept as written, because "which spec pages reference this" is a separate and factual question.

func Inside added in v0.6.0

func Inside(root, dir, what string) error

Inside reports whether dir sits inside root once every directory component has been resolved, naming root as what in the refusal. A directory that does not exist yet is judged by the nearest one above it that does, since it will be created there: a missing directory under a link out of root was passed, and creating it put the write outside.

func LineEnding

func LineEnding(source []byte) string

LineEnding is the ending a file uses, so that an edit does not leave it with a mixture. The first line decides it. Three packages were deciding this separately, and one of them forgot.

func LinkDestination

func LinkDestination(path string) string

LinkDestination renders a path as a markdown link destination, percent- encoding every character that would otherwise end the destination, the link, or the table cell around it.

One function, because the index and the link rewriter each rendered destinations their own way and only one of them escaped anything. Encoding rather than escaping, because the two interact: the angle-bracket form this replaces turned a path's ">" into "\>", and a backslash already in the path then paired with that backslash and let the ">" close the destination early. An ordinary path contains none of these and comes through unchanged, and Document.Links decodes on the way back in, so the two are inverses.

func Renumber

func Renumber(r *Repo, from, to string, frozen func(*Document) bool) (changed, unchanged []string, err error)

Renumber changes a numbered document's identifier, rewriting the filename, the front matter id, the heading, and every reference to the old identifier or the old file, in the document itself and in every other.

The number lives in three places inside its own document and in an unbounded number of places outside it, so doing this by hand reliably trades one lint error for another. Two concurrent pull requests taking the same number is the case that makes it routine.

When another document still claims the old identifier, as when two branches each took the same next number, an identifier in a front matter list or a wiki link cannot say which document it means. Those are left alone and each line holding one is returned as unchanged, as path:line: text and marked where the document is frozen, for the author to repoint any that meant the moved document. A link to the file says which it means, so it is still rewritten.

frozen reports whether a document may no longer be written to. Renumbering refuses when the document itself is frozen, and when any document that would have to change is, because a reference inside a frozen document could never be corrected and the rename would leave it pointing at a file that is gone. The refusal is complete: nothing is written unless everything can be.

func RequiredSections

func RequiredSections(t Type) []string

RequiredSections lists the H2 sections a type must carry, in the order they must appear. Other sections are permitted between or after them.

func Schema

func Schema(t Type) []string

Schema lists the keys a type's front matter may carry. A key outside this list is an unknown field.

func SetField

func SetField(source []byte, key string, value string) ([]byte, error)

SetField replaces the value of one front matter key, on the line it is written, and leaves everything else exactly as it was: the order of the other keys, their spacing, and any comments. Re-serialising the block through a YAML encoder would be shorter and would quietly discard all three.

The key is found in the source given, not taken from an earlier parse. A value written across lines is rewritten onto one, which moves every line beneath it, so a line number read before one edit names the wrong line by the next.

func Slug

func Slug(title string) string

Slug derives the human-readable half of a filename from a title: lowercased, runs of anything else collapsed to one hyphen, and the ends trimmed. The number is the identity; this is only for reading.

func StartOfDay

func StartOfDay(t time.Time) time.Time

StartOfDay is an instant's calendar date at midnight UTC, which is how a date written in front matter is held once parsed.

It lives beside DateLayout because every comparison between a written date and "now" needs it. Comparing a parsed date against a wall-clock instant makes the answer depend on the hour the command ran and the zone it ran in: east of UTC it read today as the future, and west of it read tomorrow as the past. That was a defect twice, in two packages, before this was shared.

func WriteFile

func WriteFile(full string, source []byte, name string) error

WriteFile writes a file, refusing to write through a symbolic link. name is what the refusal calls the path, which for a document is its repository path.

Every writer that replaces a file comes through here; CreateFile makes the one file that must not exist yet. os.WriteFile follows a symlink and truncates whatever is on the other end, so a symlinked INDEX.md committed to a repository, which git stores and clone restores, redirected `archdoc index` onto any file the user could write, reported only "INDEX.md", and exited 0.

The bytes go to a new file beside the original, renamed over it once they are all written. os.WriteFile truncated the original first, so a write that failed part way, at a size limit or on a full disk, left it cut short, and the undo that rewrote it failed the same way.

Types

type Answer added in v0.6.0

type Answer struct {
	// Line is 1-based within the file: the blockquote's first line.
	Line int
	// Text is the blockquote's lines with the leading > and one column of the
	// whitespace after it removed from each, as CommonMark removes them, so it
	// is Markdown without the quote.
	Text string
}

Answer is the blockquote a resolved question ends with.

type ChangelogEntry added in v0.6.0

type ChangelogEntry struct {
	// Line is 1-based within the file: the entry line.
	Line int
	// Date is zero where the entry is undated, including where what it begins
	// with is shaped as a date but is not one.
	Date time.Time
	// Text is the entry's lines as written, without its marker and date, each
	// later line with the item's content indentation removed where it has it,
	// a lazy line as written, and blank lines at either end dropped.
	Text string
}

ChangelogEntry is one entry of a Changelog section: an item of a top-level list in the section, whatever its marker.

type Document

type Document struct {
	Type Type
	// Path is relative to root, always slash-separated.
	Path string
	// ID is the identifier derived from the type and the filename number, such
	// as RFC-0001. Empty for spec pages, which are not numbered. This is the
	// authoritative identity; lint compares the front matter id against it.
	ID string
	// Number is the filename number for numbered types, 0 otherwise.
	Number int
	// Page is a spec page's path below spec/ without the extension, such as
	// http/routing, or a term's or a group's slug. Empty for numbered types.
	Page string

	// FrontMatter is the parsed YAML block.
	FrontMatter FrontMatter
	// Body is everything after the closing delimiter.
	Body string
	// BodyLine is the 1-based line the body starts on, so that positions
	// found in the body can be reported against the file.
	BodyLine int
	// Source is the document exactly as it is on disk, never normalised on the
	// way in, because every writer splices into it by offset.
	Source []byte
	// Problems are the faults found while reading the document. Lint decides
	// what they mean; repo only records them.
	Problems []Problem

	// UpdatedBy, ObsoletedBy and DependedOnBy hold the identifiers of the
	// documents naming this one in the matching forward list. IncludedIn holds
	// the names of the spec pages listing this document in includes. All are
	// sorted and derived, never written to the document itself.
	UpdatedBy    []string
	ObsoletedBy  []string
	DependedOnBy []string
	IncludedIn   []string
	// Groups holds the slugs of the groups listing this document, sorted and
	// derived like the lists above.
	Groups []string

	// EffectivelyObsolete is true when an accepted document obsoletes this one.
	// A claim by a draft, proposed, rejected or withdrawn document has no
	// effect.
	EffectivelyObsolete bool
	// Implemented is true for an accepted RFC or ADR that some spec page
	// includes.
	Implemented bool
	// Stale is true for a spec page including an effectively obsolete document.
	Stale bool
	// contains filtered or unexported fields
}

Document is one file in one of the type directories.

func Parse added in v0.6.0

func Parse(docPath string, source []byte) (d *Document, ok bool)

Parse reads source as the document at docPath, outside any repository, so nothing is derived and Repo is nil. It is for a document as it stands on a branch, where only what the document itself says is wanted. ok is false when docPath is not a document's path.

func Select added in v0.6.0

func Select(r *Repo, from, action string) (*Document, error)

Select finds the document a command is to act on, by path or by identifier, action naming the act in a refusal.

An identifier is not always unique: two pull requests branching from the same commit both take the next free number, and after both merge two documents carry it. ByID answers it with whichever path sorts first, so acting on the identifier alone would renumber, or accept, the other contributor's document. A path is unambiguous, so it is offered as the way through.

func (*Document) Anchors added in v0.6.0

func (d *Document) Anchors() []string

Anchors is every fragment a link into the document can name: each heading's anchor, then each explicit one. It is nil where the body is not read, as no anchor in it is known, and never nil otherwise.

func (*Document) Changelog added in v0.6.0

func (d *Document) Changelog() []ChangelogEntry

Changelog reads the document's Changelog entries, from every Changelog section in document order.

func (*Document) ChangelogProblems added in v0.6.0

func (d *Document) ChangelogProblems(decided time.Time) []Problem

ChangelogProblems is every fault L21 reports in the document's Changelog. decided is the date entries may not come after, which is the document's own for lint and the date about to be written for the accept and reject gates.

func (*Document) ClosingSection

func (d *Document) ClosingSection() (string, bool)

ClosingSection is the section that must be a document's last H2, and whether it has one at all. Most documents do not: PROCESS.md states a closing section only for a ref and for a rejected document, and extra sections may otherwise sit after the required ones.

It is the last entry of RequiredSections when that entry is a closing kind, which is what keeps this rule and the relative-order rule from contradicting each other. They did: Sources was required last and the rationale required after Sources, so a backfilled rejected document could satisfy neither, and `archdoc new --backfill --status=rejected` wrote one that could never lint clean and that L11 then forbade anyone repairing. PROCESS.md's Document structure section calls the rationale final and its Backfilling section asks only that a backfilled document carry Sources, so the rationale closes the document when both are required.

func (*Document) Contents

func (d *Document) Contents() []Entry

Contents is the document as a flat list of its headings, in document order.

func (*Document) Description added in v0.6.0

func (d *Document) Description() string

Description is a group's body after its H1, as written, or the whole body where the first heading is not an H1. It is what was parsed, whatever L10 reports, so a group whose heading is wrong still publishes its prose.

func (*Document) H1

func (d *Document) H1() (Heading, bool)

H1 returns the first heading when it is an H1.

func (*Document) H1Content added in v0.6.0

func (d *Document) H1Content() (start, end int, ok bool)

H1Content is where the H1's content lies in Source, without its markers, closing sequence or underline, so a writer can retitle it in place. ok is false where there is no H1 or it holds nothing.

func (*Document) Headings

func (d *Document) Headings() []Heading

Headings returns the body's top-level headings, in order.

func (*Document) InHeading added in v0.6.0

func (d *Document) InHeading(number int) bool

InHeading reports whether the file's line number holds a top-level heading, a setext heading's underline included. An edit inside one changes the text the section rules compare.

func (d *Document) Links() []Link

Links returns every markdown link in the body, in the order their destinations appear: inline links and images, and link reference definitions, whose destinations are targets like any other. An autolink and a link by reference are not listed; References lists the second. A footnote, [^label]:, is GitHub's and holds prose, so it is not one.

func (*Document) NotRead added in v0.6.0

func (d *Document) NotRead() (why, fix string)

NotRead is why the body is not read, as a refusal names it, and the edit that would let it be read. Both are empty where it is read.

func (*Document) Prose

func (d *Document) Prose() iter.Seq[ProseLine]

Prose iterates the lines of the body outside code blocks and HTML blocks, each with its prose text. Leaving the loop stops the walk.

func (*Document) QuestionProblems added in v0.6.0

func (d *Document) QuestionProblems(skipOpen bool) []Problem

QuestionProblems is every fault in the shape of the question sections, which L20 reports and the accept and reject gates refuse. skipOpen leaves out the Open questions sections, which L09 checks on an accepted document instead.

func (*Document) Questions added in v0.6.0

func (d *Document) Questions() Questions

Questions reads the document's question sections.

func (*Document) Read added in v0.6.0

func (d *Document) Read() bool

Read reports whether the body was read: false where it is longer than MaxBody, when every reader finds nothing in it.

func (*Document) References added in v0.6.0

func (d *Document) References() []Link

References returns each use of a link reference definition, [text][label], [label][] or [label], with the destination of the first definition of its label. Its position is its text's closing bracket.

func (*Document) Repo

func (d *Document) Repo() *Repo

Repo is the repository this document was discovered in.

func (*Document) RequiredSections

func (d *Document) RequiredSections() []string

RequiredSections is RequiredSections for the type, plus Sources when the document is backfilled. Both L08, which checks a section is present, and L14, which checks it is not empty, read this one list, so they cannot disagree about what a document must carry.

func (*Document) SectionTitles

func (d *Document) SectionTitles() []string

SectionTitles lists the document's H2 headings in order.

func (*Document) Sections

func (d *Document) Sections(title string) []Section

Sections returns every H2 with exactly this text.

func (*Document) TermEntry added in v0.6.0

func (d *Document) TermEntry() GlossaryEntry

TermEntry reads one term file. The term is the front matter title rather than the heading, because the title is what the filename and every lookup key derive from; L10 already holds the two to each other.

func (*Document) Unclosed

func (d *Document) Unclosed() bool

Unclosed reports whether the body ends inside a top-level fenced code block or HTML block only its end marker closes, a comment block among them. One inside a container is not: the blank line and unindented heading a writer appends end the container, and the block with it.

A writer splicing at the end of such a body writes inside the block: the rejection rationale appended to it would be code, or hidden, and the document would still lack the section the command reported writing.

func (d *Document) WikiLinks() []WikiLink

WikiLinks returns every [[...]] in the body: `[[`, a name holding no `[` or `]`, and `]]`, on one line, in text outside a link's or an image's text, read from the bytes as written, so an escaped bracket ends none.

type Entry

type Entry struct {
	Heading Heading
	// Text is the body as written, from the line after the heading's last, a
	// setext heading's underline, to the line before the next one.
	Text string
}

Entry is one heading and the lines beneath it, up to the next heading of any level, whatever that heading's level is.

A Section is a different unit and stays one: it is an H2 and everything under it, subsections included, which is what the required-section rules mean by the word. An entry's body holds no other entry's prose, so walking the entries reads every line of a body exactly once.

type FrontMatter

type FrontMatter struct {
	ID        string
	Title     string
	Status    Status
	Created   time.Time
	Decided   time.Time
	Depends   []string
	Updates   []string
	Obsoletes []string
	Includes  []string
	Verified  time.Time
	// Formerly lists a term's previous names, oldest first. Generation gives
	// each one an anchor, so a link written before a rename still resolves.
	Formerly []string
	// NamedBy is the document that introduced a term. It records where the
	// term came from and is not an inclusion: a term is not implementation.
	NamedBy string
	// Documents lists a group's members: an identifier names an RFC, ADR or
	// ref, and anything else names a spec page.
	Documents []string
	// Backfilled is the date the document was written to record a decision
	// taken earlier. Optional: created and decided carry the historical dates,
	// this one says when they were written down.
	Backfilled time.Time
	// AsOf is the date of the exchange a ref records. Optional; a ref carrying
	// it is a record of an exchange, which does not go out of date.
	AsOf time.Time
	// contains filtered or unexported fields
}

FrontMatter holds every field any document type may carry. Fields that do not apply to a type stay zero; lint decides which are permitted where.

func (FrontMatter) Has

func (f FrontMatter) Has(key string) bool

Has reports whether a key was written in the block, whatever its value.

func (FrontMatter) LineOf

func (f FrontMatter) LineOf(key string) int

LineOf is the line a key was written on, or 0 if it was not.

func (FrontMatter) Read added in v0.6.0

func (f FrontMatter) Read() bool

Read reports whether there is a block and it parsed as a mapping, so that what it holds is known. Where not, every key reads as absent.

func (FrontMatter) Unknown

func (f FrontMatter) Unknown() []UnknownKey

Unknown lists keys written in the block that belong to no schema.

type GlossaryEntry

type GlossaryEntry struct {
	Term   string
	Anchor string
	// Path is the term's file, relative to root and slash-separated.
	Path string
	// NamedBy is the document that introduced the term, or empty.
	NamedBy string
	// Line is 1-based within the file, at the term's heading.
	Line int
	// Paragraphs holds the definition's paragraphs as written, with comments
	// removed. Other counts the blocks beneath the heading that are not
	// paragraphs, and Above is the line of the first prose above it, or 0. A
	// well-formed entry has exactly one paragraph and nothing else; L15
	// reports the rest.
	Paragraphs []string
	Other      int
	Above      int
	// Definition is what is published: every line from the H1 to the end of
	// the file as written, with LF line endings. It holds the blocks L15
	// reports too, rather than dropping them unseen.
	Definition string
	// Formerly is the term file's `formerly`: its previous names, oldest
	// first.
	Formerly []string
}

GlossaryEntry is one term, read from its file under term/.

func (GlossaryEntry) Defined added in v0.6.0

func (e GlossaryEntry) Defined() bool

Defined reports whether the entry is a single paragraph of definition and nothing else.

type Heading

type Heading struct {
	Level int
	Text  string
	// Line is 1-based within the file.
	Line int
	// Anchor is the fragment GitHub would generate for this heading.
	Anchor string
	// contains filtered or unexported fields
}

Heading is one markdown heading in a document body.

type Key added in v0.6.0

type Key struct {
	Name string
	Type ValueType
	// Required is whether the key must be present, whatever its value, and
	// MayBeEmpty whether it may be present with no value.
	Required   bool
	MayBeEmpty bool
	// Values lists what an enum may hold.
	Values []string
}

Key is one front matter key of a type.

func Keys added in v0.6.0

func Keys(t Type) []Key

Keys lists a type's front matter keys, required keys first.

A type's schema may only ever gain optional keys. A new required key would put every frozen document in every existing repository in violation of L01, and L11 forbids the edit that would add it. A new type's keys may be required, as no existing document is of that type.

type Link struct {
	Text string
	// Target is the destination with its escapes, entities and
	// percent-encoding decoded, and Written the bytes the file holds, which a
	// consumer rewriting the destination replaces. Path and Fragment are the
	// parts before and after its first #, each decoded on its own, so an
	// encoded # in a filename stays in the path.
	Target   string
	Written  string
	Path     string
	Fragment string
	Type     LinkType
	// Line is 1-based within the file.
	Line int
	// Start and End are the columns of the destination as written, inside any
	// <...>, so a writer can replace it in the line without reparsing it.
	Start, End int
}

Link is a relative markdown link found in a body.

type LinkType

type LinkType string

LinkType is the form a link was written in. An image resolves like any other link and renders as something else entirely, so a consumer rewriting destinations has to tell them apart.

const (
	LinkInline     LinkType = "inline"
	LinkImage      LinkType = "image"
	LinkDefinition LinkType = "definition"
	// LinkReference is a use of a definition, which only References returns.
	LinkReference LinkType = "reference"
)

type Problem

type Problem struct {
	// Line is 1-based within the document, or 0 when it is not known.
	Line    int
	Message string
}

Problem is something wrong with a document, found while reading it. Lint turns problems into findings; repo does not decide severity or rule identity.

type ProseLine

type ProseLine struct {
	// Raw is the line as written. Edits are applied to this one.
	Raw string
	// Masked is Raw with every byte that is not prose a space, keeping its
	// length so that a position found here is the same column in Raw.
	// Matches are looked for in this one.
	Masked string
	// Number is the line's 1-based number in the file.
	Number int
}

ProseLine is one line of a body that is neither inside a fenced code block nor inside an HTML comment.

The two strings are a pair, and which is which matters: a caller decides from Masked and applies the edit that follows to Raw, at the same offsets. They are named fields rather than adjacent parameters of the same type because confusing the two is the single root cause of three defects this package has shipped.

type Question added in v0.6.0

type Question struct {
	Heading Heading
	// Detail is the lines from the line after the heading to the answer, or to
	// the next heading or the end of the document where there is no answer, as
	// written.
	Detail string
	// Answer is the blockquote a resolved question ends with. Nil for an open
	// question, and for a resolved one that ends with something else.
	Answer *Answer
}

Question is one level three heading in a question section.

type Questions added in v0.6.0

type Questions struct {
	Open     []Question
	Resolved []Question
}

Questions are a document's questions, each list in document order across every section of its name.

type Repo

type Repo struct {
	// contains filtered or unexported fields
}

Repo is a spec repository: its configuration and every document under root.

func Open

func Open(c *config.Config) (*Repo, error)

Open discovers and parses every document under the configured root.

func (*Repo) ByID

func (r *Repo) ByID(id string) *Document

ByID returns the document with this identifier, or nil. The identifier is the one derived from the type and filename, not whatever the front matter claims.

func (*Repo) ByPage

func (r *Repo) ByPage(page string) *Document

ByPage returns the spec page with this name, or nil.

func (*Repo) ByPath

func (r *Repo) ByPath(path string) *Document

ByPath returns the document at this path relative to root, or nil.

func (*Repo) Config

func (r *Repo) Config() *config.Config

Config is the configuration this repository was opened with.

func (*Repo) CreateFile added in v0.6.0

func (r *Repo) CreateFile(docPath string, source []byte, created *bool) error

CreateFile writes a document that must not exist yet, refusing anything in its place, a dangling symbolic link included. created is set once the file exists, so a caller undoing the write removes only what it made.

func (*Repo) Documents

func (r *Repo) Documents() []*Document

Documents returns every document, ordered by path.

func (*Repo) File

func (r *Repo) File(docPath string) string

File is the absolute location of a document path, which is stored slash-separated and relative to root.

func (*Repo) Glossary

func (r *Repo) Glossary() (entries []GlossaryEntry, ok bool)

Glossary lists every term, in ascending case-insensitive order of the term, which is the order GLOSSARY.md is generated in. ok is false when the repository has no term directory, which is permitted: a repository need not have a glossary at all.

Terms are files rather than sections of one page, so uniqueness is the filesystem's answer and ordering is decided here rather than checked.

The entries are built once, as the documents they are read from never change once read, and each caller is given its own slice: built for each call, link asking once per link into the glossary was quadratic.

func (*Repo) Member added in v0.6.0

func (r *Repo) Member(name string) *Document

Member returns the document a group's member names, or nil. An identifier names an RFC, ADR or ref, and anything else a spec page, so a member never resolves to a term or another group, whatever it is called.

func (*Repo) Next

func (r *Repo) Next(t Type, title string) (id, path string, err error)

Next returns the identifier and path a new document of this type would take. The number is one past the highest in the directory, so a gap left by a document that was never written is not reused.

func (*Repo) Term

func (r *Repo) Term(name string) (GlossaryEntry, bool)

Term finds a glossary entry by name, case-insensitively as uniqueness is defined. It is a map lookup rather than a scan, because link asks once per candidate on every prose line.

func (*Repo) Unread added in v0.6.0

func (r *Repo) Unread() []string

Unread lists the paths of the documents whose body is not read, which a command reading every document's links cannot see into.

func (*Repo) With added in v0.6.0

func (r *Repo) With(docPath string, source []byte) *Repo

With returns a copy of the repository in which the document at docPath reads as source, with every relationship derived again. The receiver is not changed. A transition judges what it is about to write this way, because what lint reports about a document depends on the rest of the repository. docPath names a document already in it.

func (*Repo) WriteFile

func (r *Repo) WriteFile(docPath string, source []byte) error

WriteFile puts a rewritten document back where it came from. Writing through the repository keeps the path translation and the permission bits in one place rather than at every call site that rewrites a document.

type Section

type Section struct {
	Heading Heading
	// Text is the section's body as written, which is what a rewrite needs.
	Text string
	// contains filtered or unexported fields
}

Section is a heading and everything under it, up to the next heading of equal or higher level.

func (Section) Empty

func (s Section) Empty() bool

Empty reports whether a section holds nothing but whitespace and HTML comments. This is what makes a comment count as nothing throughout: the same definition drives L14 and the pre-freeze gate.

type Status

type Status string

Status is the lifecycle status of an RFC or ADR. Spec pages and refs have none.

const (
	StatusDraft     Status = "draft"
	StatusProposed  Status = "proposed"
	StatusAccepted  Status = "accepted"
	StatusRejected  Status = "rejected"
	StatusWithdrawn Status = "withdrawn"
)

func StatusIn

func StatusIn(source []byte) Status

StatusIn reports the status recorded in a document's front matter, without reading the rest of it. L11 uses it to ask what a document looked like on the branch.

func (Status) Permitted added in v0.6.0

func (s Status) Permitted(strict bool) []Status

Permitted lists the statuses a document may move to from this one, in the order a chooser should offer them. A terminal status has none: to change what an accepted document says, write a new one that updates or obsoletes it.

It lives here rather than beside the transitions because lint judges a pull request's changes of status by the same table, and lifecycle imports lint.

func (Status) Terminal

func (s Status) Terminal() bool

Terminal reports whether a status is final. A document in a terminal status is frozen once it reaches the branch.

type Type

type Type string

Type is one of the six types of document, and also the directory each type lives in.

const (
	TypeRFC  Type = "rfc"
	TypeADR  Type = "adr"
	TypeRef  Type = "ref"
	TypeSpec Type = "spec"
	TypeTerm Type = "term"
	// TypeGroup lists documents that belong together. It records no decision
	// and carries no status, so it is never frozen, and grouping a frozen
	// document is an edit to the group rather than to the document.
	TypeGroup Type = "group"
)

func ParseIdentifier

func ParseIdentifier(id string) (Type, int, bool)

ParseIdentifier reads an identifier back into the type and number it names.

func ParseType

func ParseType(s string) (Type, bool)

ParseType turns user input into a Type. Type is a string type with no constructor, so Type("nonsense") is otherwise a perfectly valid value and every caller would need its own list of the real ones.

func TypeOf

func TypeOf(p string) (Type, bool)

TypeOf classifies a path relative to root. ok is false when the path is not a document: the wrong extension, outside the type directories, or nested in a type that does not permit subdirectories.

func (Type) HasLifecycle

func (t Type) HasLifecycle() bool

HasLifecycle reports whether documents of this type move through statuses. A spec page reflects what has already been decided and a ref records something outside the project, so neither has a status at all.

func (Type) Normative

func (t Type) Normative() bool

Normative reports whether a document of this type may be named in a depends or includes list. Those name designs and decisions; a ref is informational and is cited from the body instead.

It answers the same as HasLifecycle today and is a separate question: one is about whether a document can change state, the other about whether anything may rest on it. A later type would very likely separate them.

func (Type) Numbered

func (t Type) Numbered() bool

Numbered reports whether documents of this type carry an identifier derived from a number in the filename. Spec pages are named by path instead, a term by its slug, which is the term itself, and a group by its slug.

func (Type) WithArticle added in v0.6.0

func (t Type) WithArticle() string

WithArticle is a numbered type as a message names it: an RFC, an ADR, a ref.

type UnknownKey

type UnknownKey struct {
	Name string
	Line int
}

UnknownKey is a front matter key belonging to no schema, and where it was written.

type ValueType added in v0.6.0

type ValueType string

ValueType is the type of a front matter key's value.

const (
	ValueString ValueType = "string"
	ValueDate   ValueType = "date"
	ValueList   ValueType = "list"
	ValueEnum   ValueType = "enum"
)
type WikiLink struct {
	Name string
	Line int
	// Start and End are the columns of the whole [[...]] in its line.
	Start, End int
	// Heading is whether the link is in a heading, where link leaves it: the
	// heading's text is what L08, L09, L10 and anchors read.
	Heading bool
	// Embed is whether an unescaped ! comes straight before it, as in
	// Obsidian's ![[X]], where link leaves it: expanded, it would be an image.
	Embed bool
}

WikiLink is an unexpanded [[...]] reference.

Jump to

Keyboard shortcuts

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