@tmlmt/cooklang-parser / formatDiagnostic
Function: formatDiagnostic()
formatDiagnostic(
diagnostic,source,label?):string
Renders a single Diagnostic as a human-readable string with a source code frame (caret pointer) when span information is available.
Parameters
diagnostic
The diagnostic to render.
source
string
The original text returned in DiagnosticError.source or stored on DiagnosticError.source. Span positions refer to this string.
label?
string = "recipe"
Optional label shown in the location marker (default "recipe").
Returns
string
A multi-line plain-text string.
Example
error[COOKLANG_E0101]: Invalid quantity format: "%two"
┌─ recipe:1:12
│
1 │ Add @flour{%two}
│ ^^^^
= fix: Use a number (3), range (1-2), or fraction (1/2).
= see: https://cooklang-parser.tmlmt.com/v3/e/cooklang_e1001