Documentation
¶
Overview ¶
Package hardwrap reports a paragraph, list item, blockquote, table row or heading whose SOURCE spans more than one line.
The standard it mechanizes is one sentence: write each of those as ONE physical line, however long. A renderer decides where a rendered line ends; a newline inside a block is therefore a decision about the SOURCE, and it costs a diff line per reflow, an inconsistent line length per paragraph, and a merge conflict per neighbouring edit.
That is what makes this rule EXACT rather than heuristic. It is not "lines look short here" — it is "this block occupies more than one line", which a parse answers with certainty. The parse is the whole design: every construct that LOOKS like a run of wrapped prose and is not one — a table's rows, consecutive list items, a fenced example, front matter — is simply a different node.
Strict by default ¶
A run reports EVERY line ending inside a block, whatever the source did to spell it. The format's own spellings for a break meant to be seen are not exempt, because an exemption available per line is not an exemption — it is the rule's off switch, reachable one line at a time by anyone who learns it, and a rule with an off switch measures how well a writer knows the switch.
A document whose breaks really are authored — a poem, an address, a transcript — is served by AuthoredBreaks, which is a deliberate, reviewable line in that repository's own configuration rather than a per-block escape. See Settings.
The exemptions, both of them ¶
The one CONSTRUCT exempt in every run is a GitHub alert marker (`> [!NOTE]` and its four siblings), which is not a spelling of a line ending at all: the marker must stand alone on its blockquote's first line for the alert to exist, so joining it deletes the construct rather than reflowing it. The five types GitHub defines are the whole list, matched by an ASCII fold — see [asciiUpper] for the forgery a Unicode one admitted.
The one DOCUMENT exempt in every run is a licence: any file whose stem is `license` or `licence`, whatever its extension and however the run is configured. A licence's text is a quotation of somebody else's words, and reflowing it changes a document whose whole value is being unchanged. This clause was mechanized before it was written down, which is the enumeration running in one direction only — the code exempted a document the rule never promised to skip, so no case, no forgery probe and no reviewer was ever sent to look at it. Found by an adversarial review.
What this rule does not see ¶
Four limits are known, measured and accepted rather than guessed at:
- Prose inside an HTML BLOCK is not judged. Its lines are markup a renderer passes through verbatim, and the standard governs a paragraph, a list item, a blockquote, a table row and a heading — an HTML block is none of them. REMEASURED 2026-08-15, over the trees this analyzer actually walks: 60 multi-line HTML blocks fleet-wide, in 20 files, of which 14 hold two or more plain-text lines and six of those are first-party — GitHub issue and pull-request templates, one Hugo content page and one imported overview. The figure this comment carried for three days was 1,775, and it reproduces only with the command's prune list REMOVED (1,771), which counts the `node_modules` and vendored build trees no run ever reads. A measurement taken over a corpus the analyzer does not walk is not evidence about this analyzer, and this one overstated its own population thirtyfold in the direction that made the exemption look cheap. What the exemption costs at the true population is that any hard-wrapped passage goes silent when it is wrapped in `<div>` and `</div>`, which is an off switch reachable per block.
- A wrapped TABLE ROW is not judged, and cannot be. Inside a GFM table every source line is a row of its own, so a row broken across lines is two rows and joining them would MERGE them rather than reflow one; a cell's line segments come from its own row line and never number more than one. A would-be row broken across lines with no delimiter row above it is not a table to the parser and is reported as the paragraph it is. The rule names a table row because the standard does; the construct that would violate it does not exist in the format.
- A CR-only line ending (a pre-OSX Macintosh document) is not a line ending to the parser this rule uses, so such a document is one long line and reports nothing. CommonMark itself counts a lone carriage return as a line ending; goldmark does not. Fleet count: zero.
- A Hugo shortcode (`{{< tabs >}}`) is ordinary paragraph text to a CommonMark parser, so a shortcode broken across lines is reported as a wrapped paragraph. Measured fleet-wide before it was left alone: zero shortcode use, so mechanizing it would have cost every run something to detect nothing.
A DEFINITION LIST is deliberately not read as one — see [newParser]. Under the extension, every line above a `:` is a term of its own, so one appended line silenced a whole passage; the fleet holds none, and GitHub renders the same text as one paragraph.
Index ¶
Constants ¶
const Category = "docs"
Category is the language group this analyzer belongs to, used by the yze suite to run it only when processing documentation.
const ErrBreaksSetting errs.Const = "the break setting is not one this rule defines"
ErrBreaksSetting reports a break setting this rule does not define. An unrecognised value is REFUSED rather than read as the default: a run configured with a word this rule does not have would otherwise report the same as an unconfigured one, and nothing would say which of the two it was.
const ErrDocumentPath errs.Const = "a document entry is a file name or an extension, never a path"
ErrDocumentPath reports a configured entry that names a path. An entry is matched against a file's whole NAME or its extension, neither of which can hold a separator, so `docs/notes.txt` claims nothing — and claiming nothing silently is how a repository comes to believe it is being read. It is refused rather than trimmed to the name it contains, because the two mean different things and only the author of the line knows which was meant.
const ErrNoPaths errs.Const = "no paths to analyze"
ErrNoPaths reports a run given nothing to analyze. A runner whose root placeholder expands to nothing would otherwise green the gate over a repository no analyzer ever looked at.
const ErrNotRegularFile = goyze.ErrNotRegularFile
ErrNotRegularFile reports a named path whose contents cannot be read as a document. It IS the shared sentinel rather than a local copy: the refusal is raised by the discovery this command walks with, and a caller matching a local copy would match only for as long as the two happened to carry the same text.
const ErrNotText errs.Const = "document is not valid UTF-8 text"
ErrNotText reports a document whose bytes are not text. A markdown parser given arbitrary bytes still produces blocks, so a binary file would yield findings invented from whatever byte happened to end a line.
const ErrReadFile errs.Const = "cannot read documentation file"
ErrReadFile reports a document that could not be read.
const ErrTooDeep errs.Const = "document nests deeper than this rule reads"
ErrTooDeep reports a document whose containers nest past what this rule will parse. See [nestingLimit] for why a bound on bytes is not a bound on cost.
const ErrTooLarge = goyze.ErrTooLarge
ErrTooLarge reports a file past the size this rule will read. It IS the shared sentinel rather than a second one beside it: the bound is enforced in two places — here, and at the one place the command reads a file — and two sentinels for one condition make `errors.Is` answer false for whichever layer a caller had not thought of.
const Name = "hardwrap"
Name is the analyzer's stable identifier — the suffix of its flat rule id and the key the yze suite catalogs it under.
const Rule = Tool + "/" + Name
Rule is the stable, flat rule id every diagnostic carries: "yze/" + Name.
const SizeLimit goyze.ByteCount = 8 << 20
SizeLimit is the largest document read, in bytes. It is exported so the command can refuse a file from its directory entry, BEFORE opening it — asking afterwards costs the file's own size for a rule that then declines to apply. It is generous by three orders of magnitude over any real document, so it bounds the pathological case without ever turning away prose.
const Tool = "yze"
Tool is the suite name stamped on every diagnostic.
Variables ¶
This section is empty.
Functions ¶
func Diagnostics ¶
Diagnostics reports the hard-wrapped blocks of one document.
settings decides whether this path is prose at all — markdown by extension, and anything else only where the run was configured to read it — and how a line ending is judged. A path the run does not read yields no findings and no error: it is not this rule's business, which is a different answer from "it is clean".
A document that is not text yields ErrNotText, so the caller surfaces a tool failure rather than a clean pass over a file nobody read.
func Report ¶
func Report(read FileReader, files, unreadable []string, settings Settings) goyze.Report
Report runs the rule over each document and aggregates the diagnostics into the lean stickler-json report.
unreadable is what the walk could not read: a directory it could not enter, and a file it could not have read had it tried — a FIFO, a device, a link resolving to nothing. One this run WOULD have read is REPORTED rather than skipped, because a document the gate cannot open is where an unchecked one would hide, and it is reported THROUGH this function rather than beside it: prepending those findings after the fact put them outside the run's limit, so a tree of unreadable directories was the one unbounded path left in a bounded report.
WHICH of them arrive here is the caller's decision and not this function's, and that split is deliberate. The shared walk reaches its unreadable arms BEFORE it asks whether an analyzer claims the path, so the list it hands back carries entries of any name — a live ssh-agent socket and a dangling `.go` symlink were two of the error-severity `yze/hardwrap` findings a fleet sweep produced, and neither has a remedy an author can take. Bounding that needs two facts: whether this run would have read the path, which is the analyzer's Documents, and whether the path is a TREE nobody looked inside, which only the filesystem knows. The command holds both — see its `reportable` — and this function reports what it is given, so one limit still governs everything the run emits. Found by an adversarial review.
Types ¶
type Breaks ¶
type Breaks int
Breaks says how this run reads a block that spans lines. The zero value is StrictBreaks, so a caller that constructs a Settings without naming one gets the standard rather than the exception — the safe direction for a value nobody remembered to set.
const ( // StrictBreaks judges a block by the standard: one physical line, whatever // the source does to end its lines. It is the default because every // alternative spelling of a line ending is also a way to keep hard-wrapping // with the gate green, and a rule with a spelling that turns it off is a // rule that measures how well a writer knows the spelling. StrictBreaks Breaks = iota // AuthoredBreaks judges only the line endings the format discards, leaving // the ones it renders. It exists for a document whose breaks really are // authored — a poem, an address, a transcript — and it is a deliberate, // reviewable line in the repository that holds such a document rather than // a default, and a property of the run rather than of a line. AuthoredBreaks )
type Documents ¶
type Documents map[selector]bool
Documents is the set of file kinds a run reads. It is a value passed in rather than ambient state, so the analyzer, the command's discovery and every test agree about which files are in scope by construction — a walk that claims a file the analyzer then declines to read reports nothing about it and says nothing about having skipped it.
func ConfiguredDocuments ¶
ConfiguredDocuments is DefaultDocuments plus whatever this run was told to read as well. It is a function of an injected lookup rather than a package variable so a test sees a configuration change without exporting one, and so an unset variable is plainly the default set rather than a nil surprise.
The defaults are ADDED to rather than replaced. A configuration that could turn markdown off would let a repository opt out of the rule entirely from a file the rule itself cannot see, which is the audit-trail-free opt-out every gate has to refuse.
An entry this run cannot apply is an ERROR rather than an entry ignored. See ErrDocumentPath: configuration that does nothing and says nothing is the worst of the three possible outcomes, because the repository that wrote it believes the opposite of what is happening.
func DefaultDocuments ¶
func DefaultDocuments() Documents
DefaultDocuments is the set read with no configuration at all: markdown, by its two extensions.
func (Documents) Reads ¶
Reads reports a path this run analyzes: a licence never, and otherwise any file whose whole name or whose extension was configured.
A set naming NOTHING is the default set rather than a set that reads nothing. The zero value of a Settings carries a nil map, and a rule that read no file under it would report a clean run over every document in a repository — the one outcome a gate must never produce, reached by forgetting a field. The defaults can only be added to, so this is the same refusal as the one that keeps a configuration from turning markdown off.
type FileReader ¶
FileReader reads a file's bytes; injected so aggregation is testable without the filesystem.
type Settings ¶
Settings is everything one run was configured with: which files it reads, and how it reads a line ending. It is a value passed in rather than ambient state, so the analyzer, the command's discovery and every test agree by construction about what this run is.
func ConfiguredSettings ¶
ConfiguredSettings is the run this environment describes, or the first refusal its configuration earns. A configuration that cannot be applied is an ERROR rather than a run that quietly does something else — a setting nobody can see take effect is indistinguishable from one nobody set.
func DefaultSettings ¶
func DefaultSettings() Settings
DefaultSettings is the run with no configuration at all: markdown by its two extensions, judged by the standard.