# Snippets and their canonical form

A finding is about a snippet: the smallest expression, or member of a
declaration, that holds the signal. Each snippet has two forms.

## Its canonical form

Signals, ignores and taught snippets match on the canonical form: the
graph fragment with its structure normalised and its names kept. So
`total_price * 100`, `100 * total_price`, and `var factor = 100` then
`total_price * factor` are one pattern. To get there:

- Operands of `+`, `*`, `==`, `!=`, `and` and `or` are sorted, and chains
  of one of them flattened, so grouping doesn't matter.
- `>` and `>=` become `<` and `<=` with the sides swapped.
- Numbers lose their spelling (`100`, `100.0`, `1_00`), and constants
  folded together are one.
- A named constant is its value, and a variable that is never reassigned
  is followed to its value.
- Exactly equivalent forms are one, so `x / 0.01` is `x * 100` and
  `x * 0.01` is `x / 100`.

A BLAKE3 hash of the canonical form, 16 hex digits, is its index, and the
canonical form itself confirms a match.

## Its text

The snippet's text is the source as `jadpo fmt` writes it, comments
removed. Its hash, 16 hex digits of BLAKE3 too, is what `jadpo suggest
share` sends. It never depends on the version of the code that makes the
canonical form, and only lines written the same way in many projects reach
HQ's threshold.
