Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ematipico
Copy link
Member

Summary

Closes #7839

I added a small utility that tracks the quotes while consuming characters inside a script, and if we're inside an Astro fence block. we check if there aren't any more quotes before emitting the correct token.

Test Plan

Added new tests

I also moved the testing files inside the relative folders (vue/, svelte/ and astro/)

Docs

@changeset-bot
Copy link

changeset-bot bot commented Oct 28, 2025

🦋 Changeset detected

Latest commit: 344fec8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added A-Parser Area: parser L-HTML Language: HTML and super languages labels Oct 28, 2025
@ematipico ematipico requested review from a team October 28, 2025 09:23
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 28, 2025

Walkthrough

Adds a quote-tracking mechanism (private QuotesSeen) to the HTML lexer to record single, double and template quotes while consuming embedded languages under AstroFencedCodeBlock. The lexer uses this state to decide whether to continue consuming an embedded segment or return to HTML_LITERAL. Includes unit tests for QuotesSeen and a new ASTRO test verifying frontmatter with a quoted triple-fence parses correctly. Also adds a changelog entry.

Suggested reviewers

  • dyc3

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title "fix(html): parse frontmatter inside quotes" directly summarises the main change in the pull request. It clearly indicates that the fix addresses a parsing issue specific to frontmatter within quoted content in HTML/Astro files. The title is concise, specific, and aligns with the changeset which implements quote-tracking logic in the HTML lexer and adds test coverage for this scenario.
Linked Issues Check ✅ Passed The linked issue #7839 requires fixing a bug where content inside template literals (specifically horizontal rules) breaks the Astro formatter. The PR implements a QuotesSeen utility to track quote state whilst consuming embedded language characters within Astro fence blocks, enabling early termination when no active quotes remain. The new test file frontmatter_in_quotes.astro directly validates this scenario, and the changelog entry confirms the fix addresses issue #7839. These changes directly satisfy the requirement to handle template-literal content without formatter failure.
Out of Scope Changes Check ✅ Passed All visible changes in the provided summary are directly scoped to addressing issue #7839. The modifications to the HTML lexer implement quote tracking for Astro fence blocks, the new test file validates the fix, the changelog entry documents the resolution, and organisational improvements to test file structure are mentioned in the PR description as part of the overall test management effort. No extraneous or unrelated changes are evident.
Description Check ✅ Passed The description clearly relates to the changeset and provides appropriate context. It references the closed issue (#7839), explains the implementation approach (quote-tracking utility for Astro fence blocks), mentions test additions, and notes organisational improvements to test file structure. The level of detail provided is sufficient for reviewers to understand the scope and rationale.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/frontmatter-astro-string

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b5e878 and 344fec8.

📒 Files selected for processing (1)
  • .changeset/clean-streets-feel.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .changeset/clean-streets-feel.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Test Node.js API
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: End-to-end tests
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Check Dependencies
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: autofix

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
crates/biome_html_parser/src/lexer/mod.rs (1)

903-955: Consider clarifying the tracking logic comments.

The tracking logic is sound for the use case, but the comments on lines 920–921, 930–931, and 941–942 could be more explicit about the state machine behaviour (i.e., increment when counter is zero and opening a quote; decrement when closing).

Example for line 920–921:

-    /// It adds a single quote if single quotes are zero and the others are greater than zero. It removes it otherwise
+    /// Tracks a single quote: increments if opening (counter is zero), decrements if closing
     fn track_single(&mut self) {

This improves readability without changing behaviour.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0dcc7e and 1b5e878.

⛔ Files ignored due to path filters (10)
  • crates/biome_html_parser/tests/html_specs/error/astro/missing_fence.astro.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/error/vue/vue_unclosed_expression.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/astro/frontmatter_in_quotes.astro.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/astro/no_fence.astro.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/astro/with_fence.astro.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/svelte/svelte_expressions.svelte.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/vue/interpolation.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/vue/multiple_expressions.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/vue/vue_expressions.vue.snap is excluded by !**/*.snap and included by **
  • crates/biome_html_parser/tests/html_specs/ok/vue/vue_expressions_escaped.vue.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (3)
  • .changeset/clean-streets-feel.md (1 hunks)
  • crates/biome_html_parser/src/lexer/mod.rs (5 hunks)
  • crates/biome_html_parser/tests/html_specs/ok/astro/frontmatter_in_quotes.astro (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
.changeset/*.md

📄 CodeRabbit inference engine (CONTRIBUTING.md)

.changeset/*.md: In changeset files, only use #### or ##### headers
Changesets should describe user-facing changes; internal-only changes do not need changesets
Use past tense for what you did in the changeset description and present tense for current behavior
For bug fixes, start the changeset description with a link to the issue (e.g., Fixed #1234: ...)
When referencing a rule or assist in a changeset, include a link to the rule/assist page on the website
Include a code block in the changeset when applicable to illustrate the change
End every sentence in a changeset with a full stop (.)

Files:

  • .changeset/clean-streets-feel.md
**/*.{rs,toml}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Format Rust and TOML files before committing (e.g., via just f)

Files:

  • crates/biome_html_parser/src/lexer/mod.rs
**/*.rs

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Document rules, assists, and their options with inline rustdoc in the Rust source

Files:

  • crates/biome_html_parser/src/lexer/mod.rs
🧠 Learnings (1)
📚 Learning: 2025-10-15T09:24:31.042Z
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-10-15T09:24:31.042Z
Learning: Lexer must implement the biome_parser::Lexer trait

Applied to files:

  • crates/biome_html_parser/src/lexer/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test Node.js API
  • GitHub Check: autofix
🔇 Additional comments (4)
crates/biome_html_parser/tests/html_specs/ok/astro/frontmatter_in_quotes.astro (1)

1-9: LGTM!

This test case clearly validates the fix for parsing frontmatter when triple fences appear inside quoted strings.

Consider adding test coverage for edge cases such as escaped quotes (e.g., `\`---\ ``) or nested quote combinations to ensure robustness. However, this is optional and can be addressed in a follow-up if needed.

crates/biome_html_parser/src/lexer/mod.rs (3)

14-14: LGTM!

The AddAssign import is correctly added to support the in-place increment operations in QuotesSeen.


169-213: Quote tracking correctly prevents false frontmatter boundaries.

The implementation properly tracks quote state whilst consuming embedded language content, allowing the lexer to distinguish between --- inside quotes and actual frontmatter boundaries.

Note: The current implementation doesn't handle escaped quotes (e.g., `\`---`). Whilst this may be out of scope for the current issue, consider whether escaped quote handling is needed for production robustness. If desired, this could be addressed in a follow-up.


957-986: LGTM!

The unit tests appropriately validate the core quote-tracking behaviour for balanced and unbalanced quote scenarios.

@ematipico ematipico changed the title fix(html): parse frontmatter inside quites fix(html): parse frontmatter inside quotes Oct 28, 2025
@ematipico ematipico merged commit 57bd662 into main Oct 29, 2025
13 checks passed
@ematipico ematipico deleted the fix/frontmatter-astro-string branch October 29, 2025 12:10
@github-actions github-actions bot mentioned this pull request Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Parser Area: parser L-HTML Language: HTML and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📝 Horizontal rule in template literal breaks Astro formatter

2 participants