Skip to main content

Eligibility

A tool finds the entries that apply to a change by computing their eligibility from the collected files (see Collecting files) and the change. An entry is eligible when all of these hold:

  1. it is in the document model: its file is collected, and neither the file nor the entry has an error (see Error reach);
  2. it is not disabled (see Attributes);
  3. it has at least one counted file (see Conditions): a changed file in its scope that no disable list switches it off for (see Disable);
  4. its <when>, if it has one, holds.

Every changed file has one or two paths:

  • An added or a modified file has one path: its path.
  • A deleted file has one path: its old path. It has no added lines. Every line of its old version is a removed line.
  • A renamed file has two paths: its old path and its new path. It is in a scope when either path is, and changed and unchanged see both. Its added lines are lines of its new version and its removed lines are lines of its old version; a hit on an added line names it by its new path and a hit on a removed line by its old path (see Running checks), whichever path made it a counted file.

A Lore file or a .loreconfig in the change is a changed file like any other, and counts for every entry whose scope holds it. The entries themselves are read from the files as the change leaves them, so an entry the change adds can be eligible for that same change, unless the tool was given a rules revision (see Collecting files).

An entry with no <scope> and no <when>, in a file with no <scope>, has the whole of its base as its scope. Unless it is disabled or switched off, it is eligible for every change to a file under its base, and an entry in a Lore folder at the repository root is eligible for every change.

An eligibility result holds four lists:

  • eligible: the id of every eligible entry, rules and contexts alike.
  • hits: the hits of the checks of every eligible rule (see Running checks).
  • excluded: every error in the document model, each naming the file, entry or .loreconfig it excludes (see Error reach).
  • warnings: every warning in the document model (missing-category, empty-scope and unknown-disabled-id), whether or not its entry is eligible; missing-src-target for every context in the document model whose target is missing, eligible or not (see Context); and unsupported-check-language and ast-grep-no-language, for eligible rules only (see Running checks).

The rule at the repository root has no scope and no condition, so it is eligible for this change. The rule under apps/api/ is eligible because the changed file is under its base. The one under the checkout folder is not:

Example 100 (eligibility)​

.lore/shop.lore
<rule id="changelog-updated" category="documentation">
A change that alters what users see adds a line to the changelog.
</rule>
apps/web/src/checkout/.lore/checkout.lore
<rule id="price-from-quote" category="functional_correctness">
A displayed price must come from the quote that produced it.
</rule>
apps/api/.lore/api.lore
<rule id="api-errors-typed" category="functional_correctness">
Every error the API returns carries a typed error code.
</rule>
Change
M apps/api/src/orders.ts
+18 throw new HttpError(500)
Expected output
{ "eligible": ["api-errors-typed", "changelog-updated"], "hits": [], "excluded": [], "warnings": [] }

A deleted file counts by its old path, and a renamed file by both of its paths. OldPrice.tsx was deleted under legacy/. Price.tsx moved from the checkout folder to the pricing folder, so it is in the scope of the rules of both. Its added line counts for both conditions, though the checkout rule counts the file by its old path only. Each rule's hit names the new path:

Example 101 (eligibility)​

apps/web/src/checkout/.lore/checkout.lore
<rule id="checkout-currency-from-settings" category="functional_correctness">
<when>
addedContains: ["'USD'"]
</when>
Checkout display text never hard-codes a currency code.
</rule>
apps/web/src/pricing/.lore/pricing.lore
<rule id="pricing-currency-from-settings" category="functional_correctness">
<when>
addedContains: ["'USD'"]
</when>
Pricing code never hard-codes a currency code.
</rule>
apps/web/src/legacy/.lore/legacy.lore
<rule id="legacy-removals-logged" category="documentation">
Removing a legacy page adds a line to the migration log.
</rule>
Change
D apps/web/src/legacy/OldPrice.tsx
-1 export const OldPrice = 1
-2 export default OldPrice
R apps/web/src/checkout/Price.tsx -> apps/web/src/pricing/Price.tsx
-3 const label = 'EUR'
+3 const label = 'USD'
Expected output
{
"eligible": ["checkout-currency-from-settings", "legacy-removals-logged", "pricing-currency-from-settings"],
"hits": [
{ "rule": "checkout-currency-from-settings", "file": "apps/web/src/pricing/Price.tsx", "line": 3, "text": " const label = 'USD'" },
{ "rule": "pricing-currency-from-settings", "file": "apps/web/src/pricing/Price.tsx", "line": 3, "text": " const label = 'USD'" }
],
"excluded": [],
"warnings": []
}

A hit on an added line in a renamed file names its new path, even for a rule that counts the file by its old path:

Example 102 (eligibility, requires regex)​

apps/web/src/checkout/.lore/checkout.lore
<rule id="checkout-currency-from-settings" category="functional_correctness">
<check>
'USD'
</check>
Checkout display text never hard-codes a currency code.
</rule>
Change
R apps/web/src/checkout/Price.tsx -> apps/web/src/pricing/Price.tsx
+3 const label = 'USD'
Expected output
{
"eligible": ["checkout-currency-from-settings"],
"hits": [
{ "rule": "checkout-currency-from-settings", "file": "apps/web/src/pricing/Price.tsx", "line": 3, "text": " const label = 'USD'" }
],
"excluded": [],
"warnings": []
}

A change to a Lore file is a change to a file under its base. Here the change adds quote-expiry-shown to the checkout's Lore file, so every rule in that file is eligible, the new one included, and so is the rule whose scope holds Lore files:

Example 103 (eligibility)​

.lore/lore.lore
<rule id="lore-rules-owned" category="documentation">
<scope>
files: ["**/.lore/**/*.lore"]
</scope>
Every new rule records its owner in its `<meta>`.
</rule>
apps/web/src/checkout/.lore/checkout.lore
<rule id="price-from-quote" category="functional_correctness">
A displayed price must come from the quote that produced it.
</rule>

<rule id="quote-expiry-shown" category="functional_correctness">
A checkout page that shows a quoted price also shows when the quote expires.
</rule>
Change
M apps/web/src/checkout/.lore/checkout.lore
+5 <rule id="quote-expiry-shown" category="functional_correctness">
+6 A checkout page that shows a quoted price also shows when the quote expires.
+7 </rule>
Expected output
{ "eligible": ["lore-rules-owned", "price-from-quote", "quote-expiry-shown"], "hits": [], "excluded": [], "warnings": [] }

Given a rules revision, the same change is judged by the rules of that revision, which do not yet hold quote-expiry-shown, so it is not eligible:

Example 104 (eligibility)​

.lore/lore.lore
<rule id="lore-rules-owned" category="documentation">
<scope>
files: ["**/.lore/**/*.lore"]
</scope>
Every new rule records its owner in its `<meta>`.
</rule>
apps/web/src/checkout/.lore/checkout.lore
<rule id="price-from-quote" category="functional_correctness">
A displayed price must come from the quote that produced it.
</rule>

<rule id="quote-expiry-shown" category="functional_correctness">
A checkout page that shows a quoted price also shows when the quote expires.
</rule>
rules:.lore/lore.lore
<rule id="lore-rules-owned" category="documentation">
<scope>
files: ["**/.lore/**/*.lore"]
</scope>
Every new rule records its owner in its `<meta>`.
</rule>
rules:apps/web/src/checkout/.lore/checkout.lore
<rule id="price-from-quote" category="functional_correctness">
A displayed price must come from the quote that produced it.
</rule>
Change
M apps/web/src/checkout/.lore/checkout.lore
+5 <rule id="quote-expiry-shown" category="functional_correctness">
+6 A checkout page that shows a quoted price also shows when the quote expires.
+7 </rule>
Expected output
{ "eligible": ["lore-rules-owned", "price-from-quote"], "hits": [], "excluded": [], "warnings": [] }

A renamed file's removed lines are hits by its old path, even when only its new path is in the rule's scope:

Example 105 (eligibility)​

apps/web/src/checkout/.lore/currency.lore
<rule id="currency-from-settings" category="functional_correctness">
<when>
removedContains: ["'USD'"]
</when>
A currency code is read from settings, never hard-coded.
</rule>
Change
R apps/web/src/legacy/Price.tsx -> apps/web/src/checkout/Price.tsx
-3 const currency = 'USD'
+3 const currency = settings.currency
Expected output
{
"eligible": ["currency-from-settings"],
"hits": [
{ "rule": "currency-from-settings", "file": "apps/web/src/legacy/Price.tsx", "line": 3, "text": " const currency = 'USD'", "side": "old" }
],
"excluded": [],
"warnings": []
}