Guide for creating high-quality, user-friendly diagnostics in Biome. Use when creating diagnostics for lint rules, adding helpful advice to error messages, implementing code frame displays, or improving diagnostic quality.
Guide for creating high-quality, user-friendly diagnostics in Biome. Use when creating diagnostics for lint rules, adding helpful advice to error messages, implementing code frame displays, or improving diagnostic quality.
compatibility
Designed for coding agents working on the Biome codebase (github.com/biomejs/biome).
Purpose
Use this skill when creating diagnostics - the error messages, warnings, and hints shown to users. Covers the Diagnostic trait, advice types, and best practices for clear, actionable messages.
Prerequisites
Read crates/biome_diagnostics/CONTRIBUTING.md for concepts
In practice, most lint rules use the RuleDiagnostic builder pattern instead of constructing advice types directly. See the Add Diagnostic to Rule section below.
Add Diagnostic to Rule
use biome_analyze::{Rule, RuleDiagnostic};
implRuleforNoVar {
fndiagnostic(ctx: &RuleContext<Self>, state: &Self::State) ->Option<RuleDiagnostic> {
letnode = ctx.query();
Some(
RuleDiagnostic::new(
rule_category!(),
node.range(),
markup! {
"Using "<Emphasis>"var"</Emphasis>" is not recommended."
},
)
.note(markup! {
"Variables declared with "<Emphasis>"var"</Emphasis>" are function-scoped, not block-scoped, which means they can leak outside of loops and conditionals and cause unexpected behavior."
})
.note(markup! {
"Consider using "<Emphasis>"let"</Emphasis>" or "<Emphasis>"const"</Emphasis>" instead."
})
)
}
}
Use Markup for Rich Text
Biome supports rich markup in diagnostic messages:
use biome_console::markup;
markup! {
// Emphasis (bold/colored)"Use "<Emphasis>"const"</Emphasis>" instead."// Code/identifiers"The variable "<Emphasis>{variable_name}</Emphasis>" is never used."// Hyperlinks"See the "<Hyperlink href="https://example.com">"documentation"</Hyperlink>"."// Interpolation"Found "{count}" issues."
}
Register Diagnostic Category
Add new categories to crates/biome_diagnostics_categories/src/categories.rs:
// Good - specific and actionable"Use 'let' or 'const' instead of 'var'"// Good - explains why"This variable is never reassigned, consider using 'const'"// Good - shows what to do"Remove the unused import statement"
Bad messages:
// Bad - too vague"Invalid syntax"// Bad - just states the obvious"Variable declared with 'var'"// Bad - no guidance"This code has a problem"
Advice Guidelines
Show, don't tell:
// Good - shows code frame
CodeFrameAdvice {
path: "file.js",
span: node.text_range(),
source_code: source,
}
// Less helpful - just text
LogAdvice {
category: LogCategory::Info,
text: markup! { "The expression at line 5 is always truthy" },
}