Checks
A <check> is a child of a rule that holds a search. When the rule is
eligible, a tool runs the search over the rule's counted files (see
Conditions), and its hits go to the reviewer with
the rule. A hit is a pointer to a line, never a verdict: a hit does not
mean the rule is broken, and no hits does not mean it passed.
A rule's added-line, removed-line and dropped-line conditions already
point at the lines they find (see Conditions). A check
is for a search that should not decide whether the rule is eligible, or
one that a condition cannot express, such as an ast-grep pattern.
A rule MAY have any number of checks. A context has none (see Context).
<check>takes one attribute,lang, the check's language. Without it, the language isregex.langwith no value, or with the empty valuelang="", isinvalid-attribute-value. Any other attribute isunknown-attribute.- This specification defines two languages,
regexandast-grep. Any otherlangvalue is kept as written: it is a language no conforming tool supports (see below), not an error. - A check's body is the lines strictly between its tags, after the entry's common indentation and then the check's own are removed (see Indentation), joined with line feeds. Nothing else is trimmed: a blank line is kept as an empty line, and spaces at the end of a line are part of the body.
- A
regexbody is one pattern in the Regex dialect. A body of two or more lines isregex-not-one-line. Otherwise, a body outside the dialect, the empty body included, isregex-outside-dialect. - A tool checks a
<check>as Children describes, and its contents last: for aregexcheck,regex-not-one-lineand thenregex-outside-dialect. A body in any other language is not checked when parsing. These two checks are part of parsing, so they bind every tool that parses Lore files, whether or not it runsregexchecks. - Every error in a
<check>is entry-level, at its opening tag line. - In the document model,
checkslists each check'slangandbody, in the order the checks appear, withlang"regex"for a check that has nolang.
A two-line regex check is an error, and so is lang with no value or
an empty one. A language this specification does not define is kept,
and an ast-grep body may span lines:
Example 80 (parse)
<rule id="currency-from-settings" category="functional_correctness">
<check>
'USD'
|'EUR'
</check>
Display text never hard-codes a currency code.
</rule>
<rule id="price-from-quote" category="functional_correctness">
<check lang>
quote\.total
</check>
A displayed price must come from the quote that produced it.
</rule>
<rule id="dates-from-locale" category="functional_correctness">
<check lang="">
toLocaleDateString\(\)
</check>
Displayed dates are formatted with the shop's locale.
</rule>
<rule id="totals-from-quote" category="functional_correctness">
<check lang="structural">
items.reduce(...)
</check>
<check lang="ast-grep">
$ITEMS.reduce(
$$$
)
</check>
Cart totals come from the quote, never from summing line items.
</rule>
{
"entries": [
{
"kind": "rule", "id": "totals-from-quote", "file": ".lore/checkout.lore",
"category": "functional_correctness", "severity": "advisory", "disabled": false,
"scopes": [{ "files": ["**"], "ignores": [] }],
"when": null,
"checks": [
{ "lang": "structural", "body": "items.reduce(...)" },
{ "lang": "ast-grep", "body": "$ITEMS.reduce(\n $$$\n)" }
],
"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": "regex-not-one-line", "file": ".lore/checkout.lore", "entry": "currency-from-settings", "line": 2 },
{ "name": "invalid-attribute-value", "file": ".lore/checkout.lore", "entry": "price-from-quote", "line": 10 },
{ "name": "invalid-attribute-value", "file": ".lore/checkout.lore", "entry": "dates-from-locale", "line": 17 }
],
"warnings": []
}
Running checks
A tool runs the checks of every eligible rule, and of no other rule. Each check searches the rule's counted files that have added lines; a deleted file has none. A hit names the rule, a side, the changed file and a line's number and text: on the new side the file's new path and an added line, on the old side the file's old path and a removed line (see Conditions). A check's hits and an added-line condition's hits are on the new side; a removed-line or dropped-line condition's hits are on the old side. An eligible rule's hits are those of its checks and those of its added-line, removed-line and dropped-line conditions. A rule has at most one hit per side, file and line, however many of its checks or conditions find that line.
A regex check has a hit for each added line whose text its pattern
matches, as Regex dialect defines.
Supporting a check language is OPTIONAL for a conforming tool, language
by language. A tool that does not support a check's language, which
includes every language this specification does not define, MUST skip
that check and report the warning unsupported-check-language for it,
at the check's opening tag line. The rule stays eligible, and its other
checks still run. Only the checks of eligible rules are reported this
way, and the document model never carries this warning. A plain agent
with no tooling MAY read any check as a hint about what to look for.
The first check has no lang, so it is a regex check. Both checks
find line 4 of Summary.tsx, which gives one hit. currency.ts is
outside the scope. The second rule is not eligible, so its check is not
run:
Example 81 (eligibility, requires regex)
<scope>
files: ["**/*.tsx"]
</scope>
<rule id="currency-from-settings" category="functional_correctness">
<check>
'(USD|EUR)'
</check>
<check lang="regex">
'EUR'
</check>
Display text never hard-codes a currency code.
</rule>
<rule id="currency-symbols-from-settings" category="functional_correctness">
<when>
addedContains: ["$"]
</when>
<check>
'USD'
</check>
Display text never hard-codes a currency symbol.
</rule>
M apps/web/src/checkout/Price.tsx
+12 const label = 'USD'
+13 const note = "EUR"
M apps/web/src/checkout/Summary.tsx
+4 return <span>{'EUR'} {total}</span>
M apps/web/src/checkout/currency.ts
+2 export const DEFAULT_CURRENCY = 'USD'
{
"eligible": ["currency-from-settings"],
"hits": [
{ "rule": "currency-from-settings", "file": "apps/web/src/checkout/Price.tsx", "line": 12, "text": " const label = 'USD'" },
{ "rule": "currency-from-settings", "file": "apps/web/src/checkout/Summary.tsx", "line": 4, "text": " return <span>{'EUR'} {total}</span>" }
],
"excluded": [],
"warnings": []
}
The first check's language is not one this specification defines, so
the tool skips it and warns. The regex check still runs. The second
rule is not eligible, so its unsupported check is not reported:
Example 82 (eligibility, requires regex)
<rule id="totals-from-quote" category="functional_correctness">
<check lang="structural">
items.reduce(...)
</check>
<check>
\.reduce\(
</check>
Cart totals come from the quote, never from summing line items.
</rule>
<rule id="refund-totals-from-quote" category="functional_correctness">
<scope>
files: ["apps/web/src/refunds/**"]
</scope>
<check lang="structural">
refund.items.reduce(...)
</check>
Refund totals come from the quote, never from summing refunded items.
</rule>
M apps/web/src/checkout/CartTotal.tsx
+3 const total = items.reduce(
{
"eligible": ["totals-from-quote"],
"hits": [
{ "rule": "totals-from-quote", "file": "apps/web/src/checkout/CartTotal.tsx", "line": 3, "text": " const total = items.reduce(" }
],
"excluded": [],
"warnings": [
{ "name": "unsupported-check-language", "file": ".lore/checkout.lore", "entry": "totals-from-quote", "line": 2 }
]
}
ast-grep checks
An ast-grep check holds one pattern for the structural search tool
ast-grep, and may span several lines. This specification follows
ast-grep 0.51.0: a pattern is read with that release's pattern
syntax, and a tool that supports ast-grep checks finds the same
matches that release finds.
- A pattern SHOULD use no metavariables other than
$NAME, which matches one node, and$$$or$$$NAME, which match zero or more nodes, and no other ast-grep feature, so that it keeps its meaning in later releases. - A file's language comes from its extension: the part of its name
after the last
., when that.is not the name's first character. Extensions are compared case-sensitively, with the table below, which is the built-in list of ast-grep 0.51.0. A renamed file's extension comes from its new path. - A file the check searches whose name has no extension in the table is
skipped,
and the tool reports the warning
ast-grep-no-languagefor it, once for each rule and skipped file. The warning'sfileis the skipped file's new path, itsentryis the rule's id, and its line is 1. - Otherwise the pattern is matched against the whole new version of the file, in its language, as ast-grep 0.51.0 matches it with its default options (no project configuration, default strictness). A match covers the lines from the line of its first character to the line of its last. Each added line that a match covers is a hit. When ast-grep 0.51.0 cannot read the pattern in a file's language, the check finds nothing in that file.
| Language | Extensions |
|---|---|
| Bash | bash, bats, cgi, command, env, fcgi, ksh, sh, tmux, tool, zsh |
| C | c, h |
| Cpp | cc, hpp, cpp, c++, hh, cxx, cu, ino |
| CSharp | cs |
| Css | css, scss |
| Dart | dart |
| Elixir | ex, exs |
| Go | go |
| Haskell | hs |
| Hcl | hcl, nomad, tf, tfvars, workflow |
| Html | html, htm, xhtml |
| Java | java |
| JavaScript | cjs, js, mjs, jsx |
| Json | json |
| Kotlin | kt, ktm, kts |
| Lua | lua |
| Markdown | markdown, md |
| Nix | nix |
| Php | php |
| Python | py, py3, pyi, bzl, bazel |
| Ruby | rb, rbw, gemspec |
| Rust | rs |
| Scala | scala, sc, sbt |
| Solidity | sol |
| Swift | swift |
| Tsx | tsx |
| TypeScript | ts, cts, mts |
| Yaml | yaml, yml |
| Zig | zig |
The pattern matches two calls in CartTotal.tsx. The first covers only
line 2, which is unchanged. The second covers lines 3 to 6, and of
those only line 4 was added. Line 7 was added, but no match covers it.
.graphql has no ast-grep language, so quote.graphql is skipped:
Example 83 (eligibility, requires ast-grep)
<scope>
files: ["**/*.{tsx,graphql}"]
</scope>
<rule id="totals-from-quote" category="functional_correctness">
<check lang="ast-grep">
$LIST.reduce($$$)
</check>
Cart totals come from the quote, never from summing line items.
</rule>
export function CartTotal({ items, fees }) {
const feeTotal = fees.reduce((sum, fee) => sum + fee, 0)
const total = items.reduce(
(sum, item) => sum + item.price,
0,
)
return <span>{total + feeTotal}</span>
}
M apps/web/src/checkout/CartTotal.tsx
+4 (sum, item) => sum + item.price,
+7 return <span>{total + feeTotal}</span>
M apps/web/src/checkout/quote.graphql
+2 total: Money!
{
"eligible": ["totals-from-quote"],
"hits": [
{ "rule": "totals-from-quote", "file": "apps/web/src/checkout/CartTotal.tsx", "line": 4, "text": " (sum, item) => sum + item.price," }
],
"excluded": [],
"warnings": [
{ "name": "ast-grep-no-language", "file": "apps/web/src/checkout/quote.graphql", "entry": "totals-from-quote", "line": 1 }
]
}