Skip to content

fix(linter): enable useOptionalChain in Astro templates#9688

Closed
raashish1601 wants to merge 1 commit intobiomejs:mainfrom
raashish1601:contributor-36/biome-9179-astro-template-optional-chain
Closed

fix(linter): enable useOptionalChain in Astro templates#9688
raashish1601 wants to merge 1 commit intobiomejs:mainfrom
raashish1601:contributor-36/biome-9179-astro-template-optional-chain

Conversation

@raashish1601
Copy link
Copy Markdown

Summary

  • enable JS semantic services for non-frontmatter Astro embeds so semantic rules can run in template expressions
  • cover useOptionalChain with an Astro check --write --unsafe CLI regression

Closes #9179.

Testing

ustfmt --check crates/biome_service/src/file_handlers/html.rs crates/biome_cli/tests/cases/handle_astro_files.rs

  • cargo test -p biome_cli -j1 check_astro_template_use_optional_chain_write_unsafe -- --nocapture (shared Windows cargo environment was too noisy to complete cleanly from this worker; added the regression snapshot directly based on the standard CLI snapshot format)

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 29, 2026

⚠️ No Changeset found

Latest commit: 1f19ca0

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 github-actions Bot added A-CLI Area: CLI A-Project Area: project labels Mar 29, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 29, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 41e3659e-d813-4f61-921f-f4a0035ea9bd

📥 Commits

Reviewing files that changed from the base of the PR and between c17e08e and 1f19ca0.

⛔ Files ignored due to path filters (1)
  • crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/check_astro_template_use_optional_chain_write_unsafe.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (2)
  • crates/biome_cli/tests/cases/handle_astro_files.rs
  • crates/biome_service/src/file_handlers/html.rs

Walkthrough

The PR extends JavaScript semantic-model support to Astro template expressions by refactoring the HTML file handler's logic for when to enable semantic services during embedded JS parsing. It introduces a test case that verifies the useOptionalChain linting rule now applies correctly to Astro template expressions, addressing a gap where the rule only worked in frontmatter.

Possibly related PRs

Suggested labels

A-CLI, A-Project, A-Linter, L-JavaScript

Suggested reviewers

  • siketyan
  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: enabling the useOptionalChain linter rule to work in Astro template expressions.
Description check ✅ Passed The description clearly explains the changes: enabling JS semantic services for Astro embeds and adding a CLI regression test for useOptionalChain.
Linked Issues check ✅ Passed The PR fully addresses issue #9179 by enabling semantic services for non-frontmatter Astro embeds, allowing useOptionalChain rule to run in template expressions as required.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing useOptionalChain in Astro templates: semantic service logic in HTML handler and test coverage for the specific issue.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Comment on lines +1239 to +1242
// Astro template expressions need semantic services for JS rules such as
// `useOptionalChain`, even though they aren't source-level snippets.
let js_services = if should_build_semantic_model
&& (is_source_level || ctx.host_file_source.is_astro())
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.

This is wrong and unsafe. Instead you should update the semantics of is_source_level to enable the semantic model for text expressions

}

#[test]
fn check_astro_template_use_optional_chain_write_unsafe() {
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.

There's no need for a cli test. Use a linter test, since it's a lint rule we're fixing

@Conaclos Conaclos added the M-Likely Agent Meta: this was likely an automated PR without a human in the loop label Mar 29, 2026
@ematipico ematipico closed this Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CLI Area: CLI A-Project Area: project M-Likely Agent Meta: this was likely an automated PR without a human in the loop

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 useOptionalChain unsafe fix applies in Astro frontmatter but fails in template

3 participants