Skip to content

fix(parser/yaml): lex directives - #10484

Merged
siketyan merged 2 commits into
mainfrom
fix/yaml-directives
Jun 1, 2026
Merged

siketyan merged 2 commits into
mainfrom
fix/yaml-directives

Conversation

@siketyan

Copy link
Copy Markdown
Member

Summary

Implemented the lexer to support YAML directives before the DIRECTIVE_END marker (---).

For example:

%YAML 1.2
---

Test Plan

Added lexer unit tests.

Docs

N/A

@siketyan
siketyan requested review from a team and l0ngvh May 27, 2026 15:17
@siketyan siketyan self-assigned this May 27, 2026
@changeset-bot

changeset-bot Bot commented May 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: c722e01

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Organic activity

No automation signals detected in the analyzed events.

View full analysis →

This is an automated analysis by AgentScan

@siketyan
siketyan force-pushed the fix/yaml-directives branch from ac477d0 to 0b03f06 Compare May 27, 2026 15:18
@github-actions github-actions Bot added A-Parser Area: parser A-Formatter Area: formatter L-Yaml Language: Yaml labels May 27, 2026

@l0ngvh l0ngvh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for pushing this @siketyan

@ematipico ematipico left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you please add new cases in the parser too? We shouldn't rely on the prettier tests; we need to build our own infra too.

@github-actions github-actions Bot added A-Linter Area: linter A-Tooling Area: internal tools L-JavaScript Language: JavaScript and super languages L-CSS Language: CSS and super languages L-HTML Language: HTML and super languages L-Grit Language: GritQL A-Type-Inference Area: type inference L-Markdown Language: Markdown labels Jun 1, 2026
Base automatically changed from fix/yaml-directive-end to main June 1, 2026 13:55
@siketyan
siketyan force-pushed the fix/yaml-directives branch from e18fdee to c722e01 Compare June 1, 2026 13:55
@github-actions github-actions Bot removed A-Linter Area: linter A-Tooling Area: internal tools L-CSS Language: CSS and super languages L-HTML Language: HTML and super languages L-Grit Language: GritQL A-Type-Inference Area: type inference labels Jun 1, 2026
@github-actions github-actions Bot removed the L-Markdown Language: Markdown label Jun 1, 2026
@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This pull request adds YAML directive lexing support to Biome's YAML parser. The lexer now recognises directives starting with % (when positioned at column 0) and consumes them via dedicated helpers. Three helper functions manage directive detection and consumption: is_at_directive() validates directive placement, consume_directive() advances through directive content, and is_at_directive_trailing_trivia() identifies directive termination points via comments or line breaks. A test file exercises various directive formats including %YAML, %TAG, and custom directives alongside explicit document markers.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: implementing YAML directive lexing support in the parser.
Description check ✅ Passed The description accurately outlines the implementation of lexer support for YAML directives with concrete examples and test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/yaml-directives

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/biome_yaml_parser/src/lexer/mod.rs`:
- Around line 552-583: Add rustdoc comments to the three new directive helper
methods to explain their purpose and behavior: document is_at_directive to state
it detects a '%' directive at column zero by checking current_coordinate and
current_byte, document consume_directive to describe it asserts the '%' start,
consumes until a break or trailing trivia and returns a LexToken with
DIRECTIVE_LITERAL, and document is_at_directive_trailing_trivia to explain the
trailing-trivia detection logic (handling '#' comment start, leading blanks, and
spaces followed by '#' or break). Use the function names is_at_directive,
consume_directive, and is_at_directive_trailing_trivia in the comments so
readers can find the implementations easily.

In `@crates/biome_yaml_parser/tests/yaml_test_suite/ok/document/directives.yaml`:
- Line 5: The test fixture containing the literal "%YAML1.2" is currently in the
ok/ suite but the lexer tokenises it as DIRECTIVE_LITERAL (no diagnostics);
either move this fixture into the err/ suite if you want to enforce the YAML 1.2
space form ("%YAML 1.2"), or keep it in ok/ and update directives.yaml to add a
brief comment explaining that the lexer permissively accepts "%YAML1.2" (and
leave directives.yaml.snap unchanged since it contains only AST/CST). Ensure you
update the test location or add the inline comment in the same fixture so
expectations match the lexer behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: df72e963-546e-4aeb-8d0c-b2422a9ca85f

📥 Commits

Reviewing files that changed from the base of the PR and between 66e3a53 and c722e01.

⛔ Files ignored due to path filters (6)
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-2-24-global-tags.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-5-9-directive-indicator.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-6-13-reserved-directives.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-6-14-yaml-directive.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_formatter/tests/specs/prettier/yaml/spec/spec-example-9-5-directives-documents.yml.snap is excluded by !**/*.snap and included by **
  • crates/biome_yaml_parser/tests/yaml_test_suite/ok/document/directives.yaml.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (2)
  • crates/biome_yaml_parser/src/lexer/mod.rs
  • crates/biome_yaml_parser/tests/yaml_test_suite/ok/document/directives.yaml

@siketyan
siketyan merged commit 42ef230 into main Jun 1, 2026
27 checks passed
@siketyan
siketyan deleted the fix/yaml-directives branch June 1, 2026 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Formatter Area: formatter A-Parser Area: parser L-JavaScript Language: JavaScript and super languages L-Yaml Language: Yaml

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants