Synthèse automatique
Guide pour rédiger des diagnostics clairs et actionnables dans le code source de Biome, en couvrant le trait Diagnostic, les types d'advices et le builder RuleDiagnostic.
Points forts
- Donne des exemples Rust complets avec la macro #[derive(Diagnostic)] et l'implémentation du trait Advices
- Présente les types d'advices intégrés (LogAdvice, CodeFrameAdvice, DiffAdvice, CommandAdvice) avec leurs champs
- Structure la rédaction autour de trois questions : quoi, pourquoi, comment corriger
- Oriente vers le pattern RuleDiagnostic utilisé en pratique par la plupart des règles de lint
Limites
- Fortement lié au dépôt Biome et à ses crates internes (biome_diagnostics, biome_analyze), peu réutilisable ailleurs
- Suppose une bonne maîtrise de Rust et des macros dérivées
- Ne couvre pas les tests de diagnostics ni la mise à jour des snapshots
À utiliser lorsqu'on ajoute ou améliore un diagnostic dans une règle de lint de Biome.
À éviter pour concevoir des messages d'erreur dans un autre projet ou un autre langage que Rust.
Analyse de sécurité
SûrThis is a pure documentation/instruction guide describing Biome's diagnostic APIs with Rust code examples. No allowed-tools are declared, and there are no shell commands, network calls, file deletions, credential handling, or obfuscated payloads. The code samples are illustrative constructs (derive macros, markup!, RuleDiagnostic builders) that a coding agent would write into a repo, not execute destructively. No meaningful execution risk.
Aucun point d'attention détecté
Comment cette analyse est faiteExemples
In Biome, add a diagnostic to the noVar lint rule that tells the user to use 'let' or 'const', with an advice mentioning 'const' when the variable is never reassigned.Review my RuleDiagnostic implementation in crates/biome_analyze and make the advice messages more actionable, following Biome's show-don't-tell principles.I want to suggest an automatic fix for this Biome rule — should I use DiffAdvice or CodeFrameAdvice, and how do I wire it into the diagnostic?name: diagnostics-development description: 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.mdfor concepts - Understand Biome's Technical Principles
- Follow the "show don't tell" philosophy
Diagnostic Principles
- Explain what - State what the error is (diagnostic message)
- Explain why - Explain why it's an error (advice notes)
- Tell how to fix - Provide actionable fixes (code actions, diff advice, command advice)
Follow Technical Principles:
- Informative: Explain, don't just state
- Concise: Short messages, rich context via advices
- Actionable: Always suggest how to fix
- Show don't tell: Prefer code frames over textual explanations
Common Workflows
Create a Diagnostic Type
Use the #[derive(Diagnostic)] macro:
use biome_diagnostics::{Diagnostic, category};
#[derive(Debug, Diagnostic)]
#[diagnostic(
severity = Error,
category = "lint/correctness/noVar"
)]
struct NoVarDiagnostic {
#[location(span)]
span: TextRange,
#[message]
#[description]
message: MessageAndDescription,
#[advice]
advice: NoVarAdvice,
}
#[derive(Debug)]
struct MessageAndDescription;
impl fmt::Display for MessageAndDescription {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "Use 'let' or 'const' instead of 'var'")
}
}
Implement Advices
Create advice types that implement Advices trait:
use biome_diagnostics::{Advices, Visit};
use biome_console::markup;
struct NoVarAdvice {
is_const_candidate: bool,
}
impl Advices for NoVarAdvice {
fn record(&self, visitor: &mut dyn Visit) -> std::io::Result<()> {
if self.is_const_candidate {
visitor.record_log(
LogCategory::Info,
&markup! {
"This variable is never reassigned, use 'const' instead."
}
)?;
} else {
visitor.record_log(
LogCategory::Info,
&markup! {
"Variables declared with 'var' are function-scoped, use 'let' for block-scoping."
}
)?;
}
Ok(())
}
}
Use Built-in Advice Types
use biome_diagnostics::{LogAdvice, CodeFrameAdvice, DiffAdvice, CommandAdvice, LogCategory};
// Log advice - simple text message
LogAdvice {
category: LogCategory::Info,
text: markup! { "Consider using arrow functions." },
}
// Code frame advice - highlight code location
// Fields: path (AsResource), span (AsSpan), source_code (AsSourceCode)
CodeFrameAdvice {
path: "file.js",
span: node.text_range(),
source_code: ctx.source_code(),
}
// Diff advice - show a TextEdit diff
DiffAdvice {
diff: text_edit, // must implement AsRef<TextEdit>
}
// Command advice - suggest CLI command
CommandAdvice {
command: "biome check --write",
}
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};
impl Rule for NoVar {
fn diagnostic(ctx: &RuleContext<Self>, state: &Self::State) -> Option<RuleDiagnostic> {
let node = 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:
define_categories! {
// Existing categories...
"lint/correctness/noVar": "https://biomejs.dev/linter/rules/no-var",
"lint/style/useConst": "https://biomejs.dev/linter/rules/use-const",
}
Create Multi-Advice Diagnostics
#[derive(Debug, Diagnostic)]
#[diagnostic(severity = Warning)]
struct ComplexDiagnostic {
#[location(span)]
span: TextRange,
#[message]
message: &'static str,
// Multiple advices
#[advice]
first_advice: LogAdvice<MarkupBuf>,
#[advice]
code_frame: CodeFrameAdvice<String, TextRange, String>,
#[verbose_advice]
verbose_help: LogAdvice<MarkupBuf>,
}
Add Tags to Diagnostics
#[derive(Debug, Diagnostic)]
#[diagnostic(
severity = Warning,
tags(FIXABLE, DEPRECATED_CODE) // Add diagnostic tags
)]
struct MyDiagnostic {
// ...
}
Available tags:
FIXABLE- Diagnostic has fix informationINTERNAL- Internal error in BiomeUNNECESSARY_CODE- Code is unusedDEPRECATED_CODE- Code uses deprecated features
Best Practices
Message Guidelines
Good messages:
// 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" },
}
Provide actionable fixes:
// Good - shows exact change
DiffAdvice {
diff: text_edit, // AsRef<TextEdit>
}
// Less helpful - describes change
LogAdvice {
category: LogCategory::Info,
text: markup! { "Change 'var' to 'const'" },
}
Severity Levels
Choose appropriate severity:
// Fatal - Biome can't continue
severity = Fatal
// Error - Must be fixed (correctness, security, a11y)
severity = Error
// Warning - Should be fixed (suspicious code)
severity = Warning
// Information - Style suggestions
severity = Information
// Hint - Minor improvements
severity = Hint
Common Patterns
// Pattern 1: Simple diagnostic with note
RuleDiagnostic::new(
rule_category!(),
node.range(),
markup! { "Main message" },
)
.note(markup! { "Additional context" })
// Pattern 2: Diagnostic with code frame
RuleDiagnostic::new(
rule_category!(),
node.range(),
markup! { "Main message" },
)
.detail(
node.syntax().text_range(),
markup! { "This part is problematic" }
)
// Pattern 3: Diagnostic with link
RuleDiagnostic::new(
rule_category!(),
node.range(),
markup! { "Main message" },
)
.note(markup! {
"See "<Hyperlink href="https://biomejs.dev/linter">"documentation"</Hyperlink>"."
})
// Pattern 4: Conditional advice
impl Advices for MyAdvice {
fn record(&self, visitor: &mut dyn Visit) -> std::io::Result<()> {
if self.show_hint {
visitor.record_log(
LogCategory::Info,
&markup! { "Hint: ..." }
)?;
}
Ok(())
}
}
Tips
- Category format: Use
area/group/ruleNameformat (e.g.,lint/correctness/noVar) - Markup formatting: Use
markup!macro for all user-facing text - Hyperlinks: Always link to documentation for more details
- Code frames: Include for spatial context when helpful
- Multiple advices: Chain multiple pieces of information
- Verbose advices: Use for extra details users can opt into
- Description vs Message: Description for plain text contexts (IDE popover), message for rich display
- Register categories: Don't forget to add to
categories.rs
References
- Full guide:
crates/biome_diagnostics/CONTRIBUTING.md - Technical principles: https://biomejs.dev/internals/philosophy/#technical
- Diagnostic trait:
crates/biome_diagnostics/src/diagnostic.rs - Advice types:
crates/biome_diagnostics/src/advice.rs - Examples: Search for
#[derive(Diagnostic)]in codebase
Du fichier au premier essai
Le téléchargement contient exactement le contenu affiché sur cette fiche. Cette copie peut différer de la dernière version du dépôt source.
Consulter la source et ses fichiers annexesCe téléchargement contient uniquement SKILL.md. Les scripts, références, modèles et dépendances éventuels ne sont pas inclus. Récupérez les fichiers nécessaires depuis la source en conservant leur arborescence avant de poursuivre.
1. Télécharger le fichier
Télécharger SKILL.mdDepuis la racine d’un projet de test, enregistrez le fichier sous .skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md, ou utilisez la commande suivante. Ce dossier sert à examiner la skill avant son installation.
Commande pour macOS/Linux ou WSL : un shell POSIX et curl sont nécessaires. Sous Windows sans WSL, utilisez le bouton de téléchargement et créez le dossier manuellement.
mkdir -p '.skill-downloads/biome-diagnostics-development-mryiqidp' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/biome-diagnostics-development-mryiqidp/download' --output '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md.part' && mv '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md.part' '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md'2. Vérifier les prérequis
Lisez SKILL.md avant de l’utiliser. Si le fichier cite des scripts ou services externes, examinez-les et préparez les accès nécessaires dans votre environnement de test.
Environnement déclaré par l’auteur : Designed for coding agents working on the Biome codebase (github.com/biomejs/biome).
Extrait original : Prerequisites
- Read
crates/biome_diagnostics/CONTRIBUTING.mdfor concepts - Understand Biome's Technical Principles
- Follow the "show don't tell" philosophy
Les plateformes de la fiche sont des indications du catalogue. Les chemins ci-dessous suivent la documentation des outils ; ils ne prouvent pas que cette skill y a été exécutée. Aucune version minimale de ces outils n’est attestée pour cette fiche.
3. Charger la skill
Après vérification, copiez le dossier complet dans le projet avec l’une des commandes ci-dessous, puis ouvrez une nouvelle session de l’outil. La commande s’arrête si un dossier du même nom existe déjà : comparez les fichiers avant de le remplacer.
Claude Code
test -f '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md' && test -s '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/diagnostics-development' && cp -R '.skill-downloads/biome-diagnostics-development-mryiqidp' '.claude/skills/diagnostics-development'Cursor
test -f '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md' && test -s '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/diagnostics-development' && cp -R '.skill-downloads/biome-diagnostics-development-mryiqidp' '.cursor/skills/diagnostics-development'Codex
test -f '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md' && test -s '.skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/diagnostics-development' && cp -R '.skill-downloads/biome-diagnostics-development-mryiqidp' '.agents/skills/diagnostics-development'OpenSkills
OpenSkills doit déjà être installé. La procédure locale install/read est contrôlée avec OpenSkills 1.5.0, qui exige Node.js ≥ 20.6.0. Aucun slug du catalogue n’est résolu automatiquement.
Installation officielle d’OpenSkillsopenskills install './.skill-downloads/biome-diagnostics-development-mryiqidp'openskills read 'biome-diagnostics-development-mryiqidp'La lecture doit afficher le contenu du fichier installé et son dossier de base. Elle ne lance ni la skill ni ses dépendances.
Pour un agent qui lit AGENTS.md, synchronisez ensuite l’index. Cette commande modifie AGENTS.md : relisez le diff avant de l’utiliser.
openskills syncMode manuel ou autre outil : joignez SKILL.md à une conversation, ou ouvrez-le dans un agent capable de lire les fichiers. Ajoutez les ressources annexes nécessaires. Il n’existe pas de dossier universel reconnu par tous les outils.
4. Faire un premier essai
Utilisez une entrée courte et fictive : un endpoint d’API, un petit document ou un brief d’interface. Dans une nouvelle conversation, joignez le fichier ou donnez son chemin à l’agent, puis adaptez cette demande :
Lis .skill-downloads/biome-diagnostics-development-mryiqidp/SKILL.md et applique ses instructions à cet exemple : [décrire une entrée de test]. Indique les fichiers, dépendances ou accès qui manquent. Produis le résultat demandé par la skill sans inventer de données ni exécuter de script non examiné.Résultat attendu : une sortie correspondant aux instructions de la skill, ou une liste précise des prérequis manquants. Une simple confirmation de lecture ne valide pas le premier usage. Si une ressource externe est indisponible, ce parcours reste à tester.
Bonnes pratiques React Hook Form
Developpement
Maîtrisez React Hook Form : évitez les anti-patterns, gérez les abonnements, et traitez correctement reset, dirty state et entrées contrôlées.
Migration Emotion vers Mantine
Developpement
Migrer les styled-components Emotion vers des composants Mantine avec style props et modules CSS. Pour convertir .styled.tsx ou supprimer les imports @emotion.
Détecteur de dérive de périmètre
Developpement
Analyse les diffs git par rapport à une intention pour détecter la dérive de périmètre, fichiers non liés et PR trop larges, puis suggère de garder, diviser ou justifier.