Skip to main content

Scope and globs

A scope says which files an entry can be broken in. A file's <scope> file block is the scope of every entry in the file, and an entry's own <scope> child narrows it (see Children).

<scope> is a structured block (see Structured blocks). Its value is a mapping with two keys, both optional:

KeyValueDefault
filesA non-empty list of globs.["**"]
ignoresA list of globs.[]
  • A path is in a scope when it matches at least one of the scope's files globs and none of its ignores globs.
  • A glob is resolved against the base of the Lore file it is in: a path matches a glob g from base b when the path is below b and the rest of the path, after b/, matches g. At the repository root, the whole path is matched. The base is compared character by character, never read as a glob. For a file in an external folder, the base is the matching directory of the governed repo (see External folders).
  • A file with no <scope> has the default scope, which holds every path under its base.
  • An entry's scope is its file's scope intersected with its own <scope>: a path is in the entry's scope when it is in both. An entry's <scope> can only narrow its file's scope, never reach a path that the file's scope leaves out.
  • A changed file is in an entry's scope when one of its paths is. Eligibility says which paths a deleted or renamed file has.

In the document model, an entry's scopes holds its file's scope (the default one when the file has no <scope>), then its own <scope> when it has one. Each has its defaults filled in and its globs resolved as Conformance examples describes.

A tool checks a <scope> in this order, and reports the first problem it finds:

  1. the checks of Structured blocks;
  2. invalid-scope, when the value is not a mapping, has a key other than files and ignores, or has a files or ignores that is not a list of strings;
  3. empty-files, when files is an empty list;
  4. each glob, those in files first and then those in ignores, each list in order: leading-slash when the glob starts with /, then invalid-glob (see Glob syntax), then glob-escapes-base when one of its /-separated segments is ...

The shape is also given as scope.schema.json; where a name above covers a value the schema rejects, that name applies instead of invalid-scope.

  • Paths in a scope are relative to the base, so a scope glob MUST NOT start with /. Only the changed and unchanged conditions allow a leading / (see Conditions).
  • A glob MUST NOT reach above its base. A .. segment is glob-escapes-base even when the glob would come back down, as in src/../lib/**. This holds for every glob, including those in changed and unchanged.
  • <scope> takes no attributes. An attribute on a file's <scope> is unknown-attribute; on an entry's, see Children.
  • Every error in a file's <scope> is file-level, and every error in an entry's <scope> is entry-level. Apart from a YAML problem, the error's line is the <scope> opening tag line.

The file's scope takes in .tsx files below the checkout folder. The second rule's own scope narrows that to cart/. cart/totals.ts is in the rule's scope but not in the file's, and apps/web/src/cart/ is outside the base, so only the first rule is eligible:

Example 57 (eligibility)​

apps/web/src/checkout/.lore/pricing.lore
<scope>
files: ["**/*.tsx"]
</scope>

<rule id="price-from-quote" category="functional_correctness">
A displayed price must come from the quote that produced it.
</rule>

<rule id="cart-total-from-quote" category="functional_correctness">
<scope>
files: ["cart/**"]
</scope>
Cart totals come from the quote, never from summing line items.
</rule>
Change
M apps/web/src/checkout/Price.tsx
M apps/web/src/checkout/cart/totals.ts
M apps/web/src/cart/CartTotal.tsx
Expected output
{ "eligible": ["price-from-quote"], "hits": [], "excluded": [], "warnings": [] }

The same glob means different paths under different bases. At the root, *.json matches only top-level files. Under apps/web/src/checkout/, it matches the files directly in that folder:

Example 58 (eligibility)​

.lore/manifests.lore
<scope>
files: ["*.json"]
</scope>

<rule id="manifest-versions-pinned" category="functional_correctness">
Dependencies in a top-level manifest are pinned to exact versions.
</rule>
apps/web/src/checkout/.lore/messages.lore
<scope>
files: ["*.json"]
</scope>

<rule id="checkout-messages-sorted" category="code_style">
Checkout message files keep their keys in alphabetical order.
</rule>
Change
M apps/web/src/checkout/messages.json
+14 "checkout.total": "Total",
Expected output
{ "eligible": ["checkout-messages-sorted"], "hits": [], "excluded": [], "warnings": [] }

ignores takes paths out of a scope. Cart.test.tsx matches the first file's files, but also its ignores:

Example 59 (eligibility)​

apps/web/src/checkout/.lore/cart.lore
<scope>
files: ["**/*.{ts,tsx}"]
ignores: ["**/*.test.{ts,tsx}"]
</scope>

<rule id="cart-total-from-quote" category="functional_correctness">
Cart totals come from the quote, never from summing line items.
</rule>
apps/web/src/checkout/.lore/tests.lore
<scope>
files: ["**/*.test.{ts,tsx}"]
</scope>

<rule id="cart-tests-use-fixtures" category="test_coverage">
Cart tests build their carts from the shared quote fixtures.
</rule>
Change
M apps/web/src/checkout/Cart.test.tsx
+8 expect(total).toBe(42)
Expected output
{ "eligible": ["cart-tests-use-fixtures"], "hits": [], "excluded": [], "warnings": [] }

An empty scope. An entry with its own <scope> gets the warning empty-scope, at its <scope> opening tag line, when each of its files globs is disjoint from each of its file scope's files globs. Both are compared as written, since they resolve against the same base. Two globs are disjoint when their heads conflict or their tails conflict:

  • A glob's head is its segments before the first segment that holds *, ?, [ or {. Two heads conflict when, at some position both of them have, their segments differ.
  • A glob whose last segment is not ** has a tail: the characters of its last segment after the last *, ?, ] or } in it, or the whole segment when it holds none of them. Two tails conflict when neither ends with the other. A glob with no tail conflicts with none.

The entry stays in the document model, and is never eligible when its globs are disjoint. This is a deliberately simple test: it can miss an entry whose scope holds nothing for another reason, which then gets no warning.

The first rule asks for Markdown files in a file whose scope holds only TypeScript files, so their tails conflict. The second rule's scope can still hold a price*.ts file. In the second file, the heads checkout and cart conflict:

Example 60 (parse)​

.lore/checkout.lore
<scope>
files: ["**/*.ts"]
</scope>

<rule id="docs-link-changelog" category="documentation">
<scope>
files: ["**/*.md"]
</scope>
A documentation change links the changelog entry it describes.
</rule>

<rule id="money-type-for-prices" category="functional_correctness">
<scope>
files: ["**/*.md", "**/price*.ts"]
</scope>
Prices are typed as `Money`, never as `number`.
</rule>
apps/web/src/.lore/checkout.lore
<scope>
files: ["checkout/**"]
</scope>

<rule id="cart-total-from-quote" category="functional_correctness">
<scope>
files: ["cart/**"]
</scope>
Cart totals come from the quote, never from summing line items.
</rule>
Expected output
{
"entries": [
{
"kind": "rule", "id": "docs-link-changelog", "file": ".lore/checkout.lore",
"category": "documentation", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["**/*.ts"], "ignores": [] }, { "files": ["**/*.md"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "A documentation change links the changelog entry it describes.",
"prose": "A documentation change links the changelog entry it describes.",
"src": null,
"sources": []
},
{
"kind": "rule", "id": "money-type-for-prices", "file": ".lore/checkout.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["**/*.ts"], "ignores": [] }, { "files": ["**/*.md", "**/price*.ts"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "Prices are typed as `Money`, never as `number`.",
"prose": "Prices are typed as `Money`, never as `number`.",
"src": null,
"sources": []
},
{
"kind": "rule", "id": "cart-total-from-quote", "file": "apps/web/src/.lore/checkout.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/src/checkout/**"], "ignores": [] }, { "files": ["apps/web/src/cart/**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "Cart totals come from the quote, never from summing line items.",
"prose": "Cart totals come from the quote, never from summing line items.",
"src": null,
"sources": []
}
],
"errors": [],
"warnings": [
{ "name": "empty-scope", "file": ".lore/checkout.lore", "entry": "docs-link-changelog", "line": 6 },
{ "name": "empty-scope", "file": "apps/web/src/.lore/checkout.lore", "entry": "cart-total-from-quote", "line": 6 }
]
}

In the first file, files is a string rather than a list, then an empty list, then a glob with a leading /, and an ignores glob climbs out of src/ and back. Each excludes only its rule. The same problems in a file's <scope> exclude the whole file, and so does an attribute on it:

Example 61 (parse)​

apps/web/.lore/web.lore
<rule id="price-from-quote" category="functional_correctness">
<scope>
files: "src/**"
</scope>
A displayed price must come from the quote that produced it.
</rule>

<rule id="currency-from-settings" category="functional_correctness">
<scope>
files: []
</scope>
Display text never hard-codes a currency code.
</rule>

<rule id="dates-from-locale" category="functional_correctness">
<scope>
files: ["/apps/web/src/**"]
</scope>
Displayed dates are formatted with the shop's locale.
</rule>

<rule id="quote-expiry-shown" category="functional_correctness">
<scope>
files: ["src/**"]
ignores: ["src/../tests/**"]
</scope>
A page that shows a quoted price also shows when the quote expires.
</rule>

<rule id="totals-from-quote" category="functional_correctness">
<scope>
files: ["src/**"]
</scope>
Cart totals come from the quote, never from summing line items.
</rule>
apps/web/src/cart/.lore/cart.lore
<scope>
files: ["/apps/web/src/cart/**"]
</scope>

<rule id="cart-total-from-quote" category="functional_correctness">
Cart totals come from the quote, never from summing line items.
</rule>
apps/web/src/checkout/.lore/checkout.lore
<scope owner="checkout">
files: ["**/*.tsx"]
</scope>

<rule id="checkout-prices-from-quote" category="functional_correctness">
Every price the checkout page shows comes from the quote.
</rule>
Expected output
{
"entries": [
{
"kind": "rule", "id": "totals-from-quote", "file": "apps/web/.lore/web.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/**"], "ignores": [] }, { "files": ["apps/web/src/**"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "Cart totals come from the quote, never from summing line items.",
"prose": "Cart totals come from the quote, never from summing line items.",
"src": null,
"sources": []
}
],
"errors": [
{ "name": "invalid-scope", "file": "apps/web/.lore/web.lore", "entry": "price-from-quote", "line": 2 },
{ "name": "empty-files", "file": "apps/web/.lore/web.lore", "entry": "currency-from-settings", "line": 9 },
{ "name": "leading-slash", "file": "apps/web/.lore/web.lore", "entry": "dates-from-locale", "line": 16 },
{ "name": "glob-escapes-base", "file": "apps/web/.lore/web.lore", "entry": "quote-expiry-shown", "line": 23 },
{ "name": "leading-slash", "file": "apps/web/src/cart/.lore/cart.lore", "entry": null, "line": 1 },
{ "name": "unknown-attribute", "file": "apps/web/src/checkout/.lore/checkout.lore", "entry": null, "line": 1 }
],
"warnings": []
}

Glob syntax​

A glob is matched against a path one segment at a time. Its segments are the parts between its / characters, and each one matches one segment of the path, except **:

SyntaxMatches
**, as a whole segmentzero or more whole segments
*any run of characters within a segment, including none
?any one character
[abc], [a-z]one character in the set
[!abc], [!a-z]one character not in the set
{a,b}any one of the alternatives
any other characteritself
  • Matching is by Unicode code point and case-sensitive, with no normalization. Apart from **, nothing in a glob matches /, so *, ? and sets stay within one segment.
  • * and ? match a . at the start of a name like any other character, so * matches dotfiles and ** matches dot-directories.
  • A tool reads each segment from left to right. A [ starts a set, which runs to its closing ]: the first ] after it, except that a ] directly after [ or [! is a member. Every character inside a set is a member or part of a range, so *, ?, [, {, } and , in a set stand for themselves.
  • A set's members are read from left to right. A character followed by - and then a character other than the closing ] forms a range x-y with them: the characters from x to y by code point. Any other - is a member only when it is the set's first or last. So [--a] is the range from - to a, and [a-] holds a and -.
  • Outside sets, a { starts alternatives, which close at the next } outside a set and are separated by each , outside a set between them. An alternative MAY be empty, and MAY hold *, ? and sets.
  • There is no escape character and no negation. A special character is matched by putting it in a set, so [[]id].tsx matches [id].tsx and [{]slug}.tsx matches {slug}.tsx. Outside sets, ] is an ordinary character, and so are } and , outside alternatives. To leave paths out, use ignores.

A glob is invalid-glob when:

  • it is empty, or one of its segments is empty (as in src//a.ts or src/) or is .;
  • it starts with !;
  • outside sets, it holds ** in a segment that is not exactly **, as in **.ts;
  • a set has no closing ] in its segment, a ^ directly follows its [, one of its ranges ends before it starts, or a - in it is neither part of a range nor its first or last member;
  • outside sets, a { has no closing } in its segment, or another { comes before that };
  • it holds a \ anywhere, in a set or not.

** matches zero segments, so apps/web/src/**/checkout/*.tsx matches apps/web/src/checkout/Price.tsx. Price.tsx starts with an uppercase letter, so [!A-Z]*.tsx does not match it. * matches the leading . of .env.production:

Example 62 (eligibility)​

.lore/web.lore
<rule id="checkout-props-typed" category="code_style">
<scope>
files: ["apps/web/src/**/checkout/*.tsx"]
</scope>
Every checkout component declares its props type.
</rule>

<rule id="checkout-helpers-pure" category="code_style">
<scope>
files: ["apps/web/src/checkout/[!A-Z]*.tsx"]
</scope>
Checkout files named in lowercase hold helpers, never components.
</rule>

<rule id="cart-components-named" category="code_style">
<scope>
files: ["apps/web/src/{cart,checkout}/*.tsx"]
</scope>
A cart or checkout component is named after its file.
</rule>

<rule id="production-env-no-secrets" category="security">
<scope>
files: ["apps/web/*.production"]
</scope>
A production environment file holds no secrets; they come from the
secret store.
</rule>
Change
M apps/web/src/checkout/Price.tsx
M apps/web/.env.production
+3 PRICE_API_URL=https://prices.acme.example
Expected output
{
"eligible": ["cart-components-named", "checkout-props-typed", "production-env-no-secrets"],
"hits": [],
"excluded": [],
"warnings": []
}

An unclosed set, an unclosed brace, ** inside a longer segment and a leading ! are each invalid-glob. A [ or { inside a set is an ordinary member, so the last rule's globs match the files pages/[id].tsx and pages/{slug}.tsx:

Example 63 (parse)​

apps/web/.lore/pages.lore
<rule id="price-from-quote" category="functional_correctness">
<scope>
files: ["src/[a"]
</scope>
A displayed price must come from the quote that produced it.
</rule>

<rule id="currency-from-settings" category="functional_correctness">
<scope>
files: ["src/**/*.{ts,tsx"]
</scope>
Display text never hard-codes a currency code.
</rule>

<rule id="dates-from-locale" category="functional_correctness">
<scope>
files: ["src/**.tsx"]
</scope>
Displayed dates are formatted with the shop's locale.
</rule>

<rule id="tests-use-fixtures" category="test_coverage">
<scope>
files: ["src/**"]
ignores: ["!**/*.test.tsx"]
</scope>
Tests build their data from the shared fixtures.
</rule>

<rule id="product-page-prices" category="functional_correctness">
<scope>
files: ["pages/[[]id].tsx", "pages/[{]slug}.tsx"]
</scope>
The product page shows the price from the product's current quote.
</rule>
Expected output
{
"entries": [
{
"kind": "rule", "id": "product-page-prices", "file": "apps/web/.lore/pages.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["apps/web/**"], "ignores": [] }, { "files": ["apps/web/pages/[[]id].tsx", "apps/web/pages/[{]slug}.tsx"], "ignores": [] }],
"when": null, "checks": [], "meta": null,
"summary": "The product page shows the price from the product's current quote.",
"prose": "The product page shows the price from the product's current quote.",
"src": null,
"sources": []
}
],
"errors": [
{ "name": "invalid-glob", "file": "apps/web/.lore/pages.lore", "entry": "price-from-quote", "line": 2 },
{ "name": "invalid-glob", "file": "apps/web/.lore/pages.lore", "entry": "currency-from-settings", "line": 9 },
{ "name": "invalid-glob", "file": "apps/web/.lore/pages.lore", "entry": "dates-from-locale", "line": 16 },
{ "name": "invalid-glob", "file": "apps/web/.lore/pages.lore", "entry": "tests-use-fixtures", "line": 23 }
],
"warnings": []
}