Conformance examples
Each conformance example gives inputs and the output a conforming tool produces from them. There are three kinds:
- a parse example gives Lore files, and any
.loreconfigfiles that apply to them, and expects the document model a tool builds from them; - an eligibility example also gives a change, and expects the eligible entries, the hits, the excluded files and entries, and the warnings;
- an audit example also gives the files the rules cite, any lock files and the date, and expects the findings of an audit (see Auditing sources).
An example is a fenced block. Its opening line starts at column 0 and is
exactly six backticks, directly followed by example, one or more spaces
or tabs, and the kind: parse, eligibility or audit. Its closing line is
exactly six backticks. An opening line inside another fenced block does
not start an example. Six backticks let an example's inputs hold
ordinary fenced code blocks. Examples are numbered in document order,
starting at 1, and belong to the section under the nearest heading
before them.
Lines of the form requires: <capability> may directly follow the
opening line. Three capabilities are defined, regex, ast-grep and
loose-given-folder: an example that requires regex or ast-grep is
run only by a tool that supports checks in that language (see
Checks), one that requires loose-given-folder only by a tool
that collects a given folder in no working copy (see
External folders), and other tools skip it.
The rest of the example is a series of sections. Each starts with a line
=== followed by a name, and runs to the next such line or to the end
of the example:
| Section | Contents |
|---|---|
=== <path> | An input file at <path> in the governed repo: the section's lines, joined with line feeds. |
=== external:<path> | An input file at <path> in the external repository described below. |
=== loose:<path> | A file of one given folder that is in no working copy, <path> relative to that folder. |
=== rules:<path> | Eligibility only. A file of the governed repo as it is at the rules revision (see Collecting files). With at least one such section, the tool is given a rules revision. |
=== remote | Eligibility and audit only, optional. One line: the governed repo's remote URL, used to match repo keys. Without it, and in every parse example, the remote is https://github.com/acme/shop. |
=== diff | Eligibility only, required. The change, in the format below. |
=== today | Audit only, required. One line: the date of the audit, YYYY-MM-DD. |
=== expect | The expected output, as JSON. |
The diff has one line per changed file, each optionally followed by that file's added and removed lines:
A <path>,M <path>andD <path>: a file added, modified or deleted.R <old> -> <new>: a file renamed from<old>to<new>.+<n> <text>: an added line. Line<n>(counted from 1) of the file named by the nearestA,MorRline above it (for a rename, the new path) is<text>, which is everything after the single space that follows<n>.-<n> <text>: a removed line. Line<n>(counted from 1) of the old version of the file named by the nearestM,DorRline above it (for a rename, the old path) is<text>, read as a+line's text is.
A + line follows an A, M or R line directly or after other +
or - lines. A - line follows an M, D or R line directly or
after other + or - lines. A + line anywhere else, such as after a
D line, is malformed, and so is a - line after an A line. Under
one file, + and - lines may come in any order. A diff has no blank
lines. Any line of a changed file's new version that is not listed as
added, and any line of its old version that is not listed as removed, is
unchanged.
What the governed repo contains. The governed repo contains exactly
the === <path> input files and every path the diff adds, modifies or
renames to, and all of them are tracked by version control. A changed
file that is not also an input file has unknown content apart from its
added lines. When a changed file is also an input file, each of its
+<n> <text> lines equals line <n> of that input. The old version of
every changed file has unknown content apart from its removed lines.
With === rules:<path> sections, the Lore files, .loreconfig files
and src targets of the governed repo are read from them only, and the
plain input files are still the governed repo as the change leaves it.
This document is UTF-8 text with line feeds, so an input file can hold
neither a carriage return nor a byte that is not valid UTF-8. The rules
for those bytes have no conformance examples.
External inputs. The === external:<path> input files are the
tracked files of one other repository, and the tool was given that
repository's root as a given folder. Each <path> is relative to
that repository's root.
Audit inputs. An audit example's input files are also the files its
sources cite. A source's file exists when the example has an input file
at exactly its resolved path, prefix included, and is absent otherwise,
so every source in an audit example could be looked at. An input named
lore-reviews.lock is the lock file in the directory that holds it
(see The lock file), and no example holds a malformed
one. The audit runs on the date in === today, and its
levels and age limits come from the example's .loreconfig files only.
Expected output. A parse example's expect is a document model,
valid against
document-model.schema.json. An
eligibility example's expect is an eligibility result, valid against
eligibility.schema.json.
Document model defines every field of both. An audit
example's expect is an audit result, valid against
audit.schema.json, whose fields
Findings defines. A tool's output
matches the expect when the two are equal as JSON values: arrays compare
item by item in order (see Order below), and objects compare regardless
of the order of their members. In every kind:
- Paths. Every
filefield is a path exactly as written in the example: after===for an input file, keeping theexternal:,loose:orrules:prefix, or in the diff for a changed file. The one exception is a diagnostic about a loose folder as a whole, which hasfileloose:.andline1 (see External folders). - Scopes. Globs in an entry's
scopesare resolved to paths from the governed repo's root: a globgin a file whose base isbappears asb/g, and a glob in a file whose base is the repo root appears asg. Theb/part is a literal path prefix, not glob syntax, since a base may hold[,{,*or?. Globs in external files resolve through theirrepomapping. - Diagnostic lines. A diagnostic's
linecounts from 1 within its file. For a YAML problem (invalid-yaml,duplicate-key,yaml-feature-not-allowed) it is the offending line, counted in the file, not the block (see Structured blocks). Fortop-level-textit is the first stray line, or the line holding text after a comment's-->. For a closing tag that closes nothing, or a malformed closing tag, at the top level or inside an entry, it is the offending line. For an invalid UTF-8 byte it is that byte's line, and for an unclosed comment the line where the comment opens. For a problem in a.loreconfig, it is the line that .loreconfig and External folders define. For any other problem in an element it is the opening tag line of the element at fault. A problem with no line has line 1. - Diagnostic entry. A diagnostic's
entryis the id of the entry the problem is in, when that entry has a readable id (see Attributes). It is null otherwise, and always null for a file-level error. - Prose and summary are computed as Entries defines.
- Hits. A hit's
lineis the+<n>or-<n>line number from the diff and itstextis that line's text; a hit on a removed line carries"side": "old"and names the file by its old path, and a hit on an added line carries noside. - Order. Entries are ordered by
file, then by position in the file. Diagnostics are ordered byfile, thenline, thenname, thenentry, null first.eligibleis in ascending order, and hits are ordered byrule, thenfile, then side with new before old, thenline. Findings are ordered as Findings says. Strings compare code point by code point.
For illustration, here is an eligibility example as it is written in this document. It is shown inside a longer fence, so it is not numbered or run:
``````example eligibility
=== .lore/rules.lore
<rule id="currency-from-settings" category="functional_correctness">
<when>
addedContains: ["'USD'"]
</when>
Display text never hard-codes a currency code.
</rule>
=== diff
M apps/web/src/checkout/Price.tsx
+12 const label = 'USD'
=== expect
{
"eligible": ["currency-from-settings"],
"hits": [
{ "rule": "currency-from-settings", "file": "apps/web/src/checkout/Price.tsx", "line": 12, "text": "const label = 'USD'" }
],
"excluded": [],
"warnings": []
}
``````