Sources
A rule's <source> names the files the rule was written from, such as
a review guide, a decision record or the code that sets a convention.
It is a structured block (see Structured blocks)
whose value is a mapping, or a list of one or more mappings. Each
mapping names one source:
| Key | Required | Value |
|---|---|---|
file | yes | One file, as a non-empty string (see File paths). |
heading | no | A non-empty string: a heading in the file, given as its text or its slug. Only when file ends in .md, .mdx or .markdown, compared case-sensitively. |
phrase | no | A non-empty string that appears in the file. With heading, it appears inside that heading's section. |
<source>takes no attributes (unknown-attribute) and may appear once in a rule (duplicate-child), as<scope>and<when>do (see Children). On a context it isunknown-child.- A tool checks a
<source>for the problems of Structured blocks first. Any other problem isinvalid-source: a value that is not a mapping or a non-empty list of mappings, a key the table above does not name, a missing or emptyfile, a value that is not a string, an emptyheadingorphrase, aheadingon a file that is not Markdown (its extension compared case-sensitively, sodocs/NOTES.MDis not Markdown), afilethat breaks the rules of File paths, and two items that resolve to the same file with the sameheadingandphrase. invalid-sourceis entry-level. Its line is the<source>opening tag line.- The shape is also given as
source.schema.json. The path rules and the rule against repeated items are not in the schema, and still giveinvalid-source. - Parsing MUST NOT read a cited file. A
<source>whose file does not exist, or does not hold itsheadingorphrase, is still valid, and its rule is read as usual. An audit finds whether a source resolves (see Auditing sources). - In the document model,
sourcesholds each item in the order written, as an object withfile,headingandphrase.fileis resolved as File paths says, andheadingandphraseare as written, or null when absent. A rule without<source>, and every context, hassources: []. - A valid
<source>does not change whether a rule is eligible.
A tool written before <source> was defined reads it as
unknown-child, which excludes only that rule. Tools are upgraded
before rule files use it.
A source given as a mapping, with a heading:
Example 84 (parse)
<rule id="money-in-minor-units" category="functional_correctness" severity="blocking">
<source>
file: docs/checkout-review.md
heading: Money is integer minor units
</source>
<when>
addedContains: ["parseFloat(", "toFixed("]
</when>
Amounts are integers in minor units (cents).
</rule>
{
"entries": [
{
"kind": "rule", "id": "money-in-minor-units", "file": ".lore/checkout.lore",
"category": "functional_correctness", "severity": "blocking", "disabled": false,
"scopes": [{ "files": ["**"], "ignores": [] }],
"when": { "addedContains": ["parseFloat(", "toFixed("] }, "checks": [], "meta": null,
"summary": "Amounts are integers in minor units (cents).",
"prose": "Amounts are integers in minor units (cents).",
"src": null,
"sources": [
{ "file": "docs/checkout-review.md", "heading": "Money is integer minor units", "phrase": null }
]
}
],
"errors": [],
"warnings": []
}
Sources given as a list keep their order, and a plain file resolves
from the base:
Example 85 (parse)
<rule id="totals-in-minor-units" category="functional_correctness">
<source>
- file: src/checkout/money.ts
phrase: 'export function fromCents('
- file: docs/checkout-review.md
heading: money-is-integer-minor-units
phrase: never a float
</source>
Cart totals are integers in minor units (cents).
</rule>
{
"entries": [
{
"kind": "rule", "id": "totals-in-minor-units", "file": "apps/web/.lore/web.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "Cart totals are integers in minor units (cents).",
"prose": "Cart totals are integers in minor units (cents).",
"src": null,
"sources": [
{ "file": "apps/web/src/checkout/money.ts", "heading": null, "phrase": "export function fromCents(" },
{ "file": "apps/web/docs/checkout-review.md", "heading": "money-is-integer-minor-units", "phrase": "never a float" }
]
}
],
"errors": [],
"warnings": []
}
A value that is not a mapping or a non-empty list of mappings is
invalid-source: a scalar, an empty list, and a list with a scalar
item:
Example 86 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
docs/pricing-review.md
</source>
A displayed price must come from the quote that produced it.
</rule>
<rule id="currency-from-settings" category="functional_correctness">
<source>
[]
</source>
Display text never hard-codes a currency code.
</rule>
<rule id="dates-from-locale" category="functional_correctness">
<source>
- file: docs/locale-review.md
- docs/dates.md
</source>
Displayed dates are formatted with the shop's locale.
</rule>
{
"entries": [],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "currency-from-settings", "line": 9 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "dates-from-locale", "line": 16 }
],
"warnings": []
}
A key the table does not name is invalid-source, whatever it means
to the author:
Example 87 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
file: docs/pricing-review.md
section: Prices
</source>
A displayed price must come from the quote that produced it.
</rule>
{
"entries": [],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 }
],
"warnings": []
}
Every item needs a file:
Example 88 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
heading: Prices
</source>
A displayed price must come from the quote that produced it.
</rule>
{
"entries": [],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 }
],
"warnings": []
}
An empty file, heading or phrase is invalid-source:
Example 89 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
file: ""
</source>
A displayed price must come from the quote that produced it.
</rule>
<rule id="currency-from-settings" category="functional_correctness">
<source>
file: docs/currency-review.md
heading: ""
</source>
Display text never hard-codes a currency code.
</rule>
<rule id="dates-from-locale" category="functional_correctness">
<source>
file: docs/locale-review.md
phrase: ''
</source>
Displayed dates are formatted with the shop's locale.
</rule>
{
"entries": [],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "currency-from-settings", "line": 9 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "dates-from-locale", "line": 17 }
],
"warnings": []
}
A value that is not a string is invalid-source, a null included:
Example 90 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
file: docs/pricing-review.md
phrase: 42
</source>
A displayed price must come from the quote that produced it.
</rule>
<rule id="currency-from-settings" category="functional_correctness">
<source>
file: docs/currency-review.md
heading:
</source>
Display text never hard-codes a currency code.
</rule>
<rule id="dates-from-locale" category="functional_correctness">
<source>
file: [docs/locale-review.md, docs/dates.md]
</source>
Displayed dates are formatted with the shop's locale.
</rule>
{
"entries": [],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "currency-from-settings", "line": 10 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "dates-from-locale", "line": 18 }
],
"warnings": []
}
A heading is only for a Markdown file. The source file is TypeScript,
so the first rule is excluded, while the second names a phrase instead:
Example 91 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
file: apps/web/src/checkout/price.ts
heading: Prices
</source>
A displayed price must come from the quote that produced it.
</rule>
<rule id="quote-total-shown" category="functional_correctness">
<source>
file: apps/web/src/checkout/price.ts
phrase: quote.total
</source>
The checkout page shows the quote's total.
</rule>
{
"entries": [
{
"kind": "rule", "id": "quote-total-shown", "file": ".lore/checkout.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "The checkout page shows the quote's total.",
"prose": "The checkout page shows the quote's total.",
"src": null,
"sources": [
{ "file": "apps/web/src/checkout/price.ts", "heading": null, "phrase": "quote.total" }
]
}
],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 }
],
"warnings": []
}
The extension is compared case-sensitively, so docs/NOTES.MD is not a
Markdown file and takes no heading:
Example 92 (parse)
<rule id="round-half-to-even" category="functional_correctness">
<source>
file: docs/NOTES.MD
heading: Rounding
</source>
Amounts are rounded half to even.
</rule>
{
"entries": [],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "round-half-to-even", "line": 2 }
],
"warnings": []
}
Two items that resolve to the same file, with the same heading and
phrase, are invalid-source, however each is written. Two items that
name one file with different headings are not:
Example 93 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
- file: docs/pricing-review.md
- file: /docs/pricing-review.md
</source>
A displayed price must come from the quote that produced it.
</rule>
<rule id="currency-from-settings" category="functional_correctness">
<source>
- file: docs/currency-review.md
heading: Codes
- file: docs/currency-review.md
heading: Symbols
</source>
Display text never hard-codes a currency code or symbol.
</rule>
{
"entries": [
{
"kind": "rule", "id": "currency-from-settings", "file": ".lore/checkout.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "Display text never hard-codes a currency code or symbol.",
"prose": "Display text never hard-codes a currency code or symbol.",
"src": null,
"sources": [
{ "file": "docs/currency-review.md", "heading": "Codes", "phrase": null },
{ "file": "docs/currency-review.md", "heading": "Symbols", "phrase": null }
]
}
],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 }
],
"warnings": []
}
An attribute on <source>, a second <source>, and a <source> on a
context are the errors every child has:
Example 94 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source kind="guide">
file: docs/pricing-review.md
</source>
A displayed price must come from the quote that produced it.
</rule>
<rule id="currency-from-settings" category="functional_correctness">
<source>
file: docs/currency-review.md
</source>
<source>
file: docs/settings.md
</source>
Display text never hard-codes a currency code.
</rule>
<context id="checkout-architecture" src="ARCHITECTURE.md">
<source>
file: docs/checkout-review.md
</source>
Read before judging any change to how a price is computed.
</context>
{
"entries": [],
"errors": [
{ "name": "unknown-attribute", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 },
{ "name": "duplicate-child", "file": ".lore/checkout.lore", "entry": "currency-from-settings", "line": 12 },
{ "name": "unknown-child", "file": ".lore/checkout.lore", "entry": "checkout-architecture", "line": 19 }
],
"warnings": []
}
File paths
file names one file, not a glob. A file that breaks these rules is
invalid-source.
- A path starting
./or../is relative to the Lore file, exactly as a context'ssrcis (see Context), and MUST stay inside the Lore root. - A path starting
/is from the governed repo's root. In an external folder it is from the root itsrepomapping stands for, which is the governed repo's root, so it names the file it would name in the governed repo. In a loose folder it is from the loose folder. - Any other path resolves from the base, or through the
repomapping in an external folder, as a plainsrcdoes. - Apart from the one leading
/, the segment rules are those ofsrc: no empty segments, and.and..only at the start. After a leading/, no segment is.or... - In the document model,
fileis the resolved path, with theexternal:andloose:prefixessrcuses: a file-relative path in an external folder isexternal:<path>, from that folder's repository's root, and a file-relative path or one with a leading/in a loose folder isloose:<path>, from the loose folder.
From a nested base, a leading / names a file from the governed repo's
root instead of from the base:
Example 95 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
- file: /docs/decisions/0042-quote-prices.md
- file: README.md
</source>
A displayed price must come from the quote that produced it.
</rule>
{
"entries": [
{
"kind": "rule", "id": "price-from-quote", "file": "apps/web/src/checkout/.lore/checkout.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/src/checkout/**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "A displayed price must come from the quote that produced it.",
"prose": "A displayed price must come from the quote that produced it.",
"src": null,
"sources": [
{ "file": "docs/decisions/0042-quote-prices.md", "heading": null, "phrase": null },
{ "file": "apps/web/src/checkout/README.md", "heading": null, "phrase": null }
]
}
],
"errors": [],
"warnings": []
}
A path starting ./ or ../ resolves from the directory that holds
the Lore file, as a context's src does:
Example 96 (parse)
<rule id="money-in-minor-units" category="functional_correctness">
<source>
- file: ./money-review.md
- file: ../money.ts
phrase: 'export function fromCents('
</source>
Amounts are integers in minor units (cents).
</rule>
{
"entries": [
{
"kind": "rule", "id": "money-in-minor-units", "file": "apps/web/src/checkout/.lore/money.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/src/checkout/**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "Amounts are integers in minor units (cents).",
"prose": "Amounts are integers in minor units (cents).",
"src": null,
"sources": [
{ "file": "apps/web/src/checkout/.lore/money-review.md", "heading": null, "phrase": null },
{ "file": "apps/web/src/checkout/money.ts", "heading": null, "phrase": "export function fromCents(" }
]
}
],
"errors": [],
"warnings": []
}
A path that leaves the Lore root, or breaks the segment rules, is
invalid-source. With no .loreconfig, the Lore root is the
repository root, so the first rule climbs above it. The others have a
.. after a named segment, an empty segment, and a .. after a leading
/:
Example 97 (parse)
<rule id="price-from-quote" category="functional_correctness">
<source>
file: ./../../handbook/review.md
</source>
A displayed price must come from the quote that produced it.
</rule>
<rule id="currency-from-settings" category="functional_correctness">
<source>
file: docs/../currency-review.md
</source>
Display text never hard-codes a currency code.
</rule>
<rule id="dates-from-locale" category="functional_correctness">
<source>
file: docs//locale-review.md
</source>
Displayed dates are formatted with the shop's locale.
</rule>
<rule id="quote-expiry-shown" category="functional_correctness">
<source>
file: /../quote-review.md
</source>
A checkout page that shows a quoted price also shows when the quote expires.
</rule>
{
"entries": [],
"errors": [
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 2 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "currency-from-settings", "line": 9 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "dates-from-locale", "line": 16 },
{ "name": "invalid-source", "file": ".lore/checkout.lore", "entry": "quote-expiry-shown", "line": 23 }
],
"warnings": []
}
In an external folder, a plain path and a leading / resolve through
the repo mapping to the governed repo, and a file-relative path stays
in the team repository. Here the Lore root is the marked directory,
lore/shop/:
Example 98 (parse)
repo: github.com/acme/shop
# Review handbook
<rule id="web-prices-from-quote" category="functional_correctness">
<source>
- file: docs/checkout-review.md
- file: /docs/decisions/0042-quote-prices.md
- file: ../../../handbook.md
heading: Prices
</source>
A price the web app displays comes from the quote that produced it.
</rule>
{
"entries": [
{
"kind": "rule", "id": "web-prices-from-quote", "file": "external:lore/shop/apps/web/.lore/web.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "A price the web app displays comes from the quote that produced it.",
"prose": "A price the web app displays comes from the quote that produced it.",
"src": null,
"sources": [
{ "file": "apps/web/docs/checkout-review.md", "heading": null, "phrase": null },
{ "file": "docs/decisions/0042-quote-prices.md", "heading": null, "phrase": null },
{ "file": "external:lore/shop/handbook.md", "heading": "Prices", "phrase": null }
]
}
],
"errors": [],
"warnings": []
}
In a loose folder, a plain path still resolves through the repo
mapping, while a leading / and a file-relative path name files of the
loose folder:
Example 99 (parse, requires loose-given-folder)
repo: github.com/acme/shop
loose: true
<rule id="web-prices-from-quote" category="functional_correctness">
<source>
- file: docs/checkout-review.md
- file: /handbook.md
- file: ./notes.md
</source>
A price the web app displays comes from the quote that produced it.
</rule>
{
"entries": [
{
"kind": "rule", "id": "web-prices-from-quote", "file": "loose:apps/web/.lore/web.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "A price the web app displays comes from the quote that produced it.",
"prose": "A price the web app displays comes from the quote that produced it.",
"src": null,
"sources": [
{ "file": "apps/web/docs/checkout-review.md", "heading": null, "phrase": null },
{ "file": "loose:handbook.md", "heading": null, "phrase": null },
{ "file": "loose:apps/web/.lore/notes.md", "heading": null, "phrase": null }
]
}
],
"errors": [],
"warnings": []
}