syntax-text-handling

Extract and store token-backed source text from Biome AST and CST syntax trees.

25.7k|1.2k|Updated Jul 27, 2023
One-click install
npx skills add https://github.com/biomejs/biome --skill syntax-text-handling
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: syntax-text-handling
Source: https://github.com/biomejs/biome/tree/main/.claude/skills/syntax-text-handling
Command: npx skills add https://github.com/biomejs/biome --skill syntax-text-handling

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Working with Biome's AST/CST source text often leads to subtle bugs: unnecessary string allocations, incorrect trivia handling, broken quote stripping, wrong range offsets, and temporary-borrow compile errors. This Skill guides coding agents to use the correct typed syntax APIs and token-backed text storage instead of ad-hoc string conversions.

Core Features & Use Cases

  • Correct Text Accessors: Choose between text_trimmed(), token_text_trimmed(), text(), and inner_string_text() based on whether trivia and quotes should be included.
  • Allocation-Free Substrings: Use TokenText::slice(), relative_range(), and source_range() to store token-relative ranges without copying strings.
  • Embedded-Language Handling: Verify framework-specific value shapes (quoted HtmlString, text expressions, directive nodes) before extracting attribute values.
  • Use Case: While writing a Biome lint rule that compares an HTML attribute value to a known string, use inner_string_text() to strip quotes correctly and compare borrowed text without allocating.

Quick Start

Use the syntax-text-handling skill to extract the quote-stripped value of this HTML attribute node and compare it against a handler name without allocating strings.

Frequently Asked Questions about syntax-text-handling

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I extract token text without trivia in Biome syntax trees?

Use SyntaxToken::text_trimmed() to borrow text without leading or trailing trivia, or token_text_trimmed() to retain a token-backed TokenText. Avoid calling to_string() or format! just to compare syntax text.

How to strip quotes from string tokens in Biome HTML syntax?

Use the inner_string_text() helper, either the free function or HtmlString::inner_string_text(), which returns quote-stripped TokenText. Do not slice bytes manually, since that duplicates language-specific logic and risks invalid boundaries.

What is the difference between text_trimmed on tokens and nodes in Biome?

SyntaxToken::text_trimmed() removes surrounding trivia from a single token, while SyntaxNode::text_trimmed() removes only outer trivia and keeps interior whitespace and comments. Node text is not a semantic accessor for multi-token nodes.

How do I store a substring of a token without allocating in Rust?

Use TokenText::slice() with a range relative to the current text; it retains the underlying green token and adjusts the selected range. relative_range() and source_range() then convert between token-relative and file ranges.

Why do I get temporary-borrow errors with Biome typed accessors?

Typed accessors return owned wrapper nodes whose tokens borrow through the wrapper, so chained expressions can drop the owner too early. Bind intermediate values to variables instead of converting to String.

When should I not use this syntax text handling approach?

Do not use it for parser implementation or formatter comment placement, which follow different rules. Also avoid it when the value genuinely must outlive its syntax tree, in which case owned strings are appropriate.