fix(html): skip unsupported <script> types instead of treating as JS (fixes #9506, #9479)#9515
Conversation
…ixes biomejs#9506, biomejs#9479) Root cause: EmbedTarget::Dynamic for the script element detector had `fallback: Some(GuestLanguage::JsScript)`. When resolve_script_language returned None for types like speculationrules or application/ld+json (which are Unsupported in ScriptType), the fallback applied JsScript, causing biome to parse non-JS content as JavaScript and report false parse errors. Fix: Remove the fallback (set to None). The resolver already returns an appropriate JS GuestLanguage for all valid JS script cases, so None from the resolver always means "skip this element".
🦋 Changeset detectedLatest commit: 6d3a70d The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
ematipico
left a comment
There was a problem hiding this comment.
Thank you. I know the fix was simple :)
WalkthroughThis pull request fixes false parse errors reported by Biome for unsupported HTML script types. Changes include modifying the script and style detector fallbacks from returning a default guest language to returning Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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. Comment Tip CodeRabbit can use Trivy to scan for security misconfigurations and secrets in Infrastructure as Code files.Add a .trivyignore file to your project to customize which findings Trivy reports. |
Summary
Fixes #9506
Fixes #9479.
The embed registry's script element detector was using
fallback: Some(GuestLanguage::JsScript)in itsEmbedTarget::Dynamicconfig. Whenresolve_script_languagereturnedNonefor types likespeculationrulesorapplication/ld+json(which areScriptType::Unsupported),EmbedTarget::resolve()applied theJsScriptfallback via.or(*fallback), causing biome to parse non-JavaScript content as JavaScript.Root Cause
In
crates/biome_service/src/embed/registry.rs,HTML_DETECTORShad:resolve_script_languagecorrectly returnsNoneforScriptType::Unsupportedtypes (lineif !script_type.is_javascript() { return None; }). However,EmbedTarget::resolve()applies the fallback when the resolver returnsNone:So
speculationrulesandapplication/ld+jsoncontent was being passed to the JavaScript parser, producing false parse errors and incorrect lint diagnostics.Solution
Remove the fallback (
fallback: None). Theresolve_script_languagefunction already returns a correctGuestLanguagefor every legitimate JavaScript script case — it only returnsNonefor unsupported types or non-HTML file sources, both of which should mean "skip this element".Testing
no_diagnostics_for_unsupported_script_typesincrates/biome_service/src/workspace/server.tests.rsthat reproduces the exact scenario from both issues: an HTML file containing<script type="speculationrules">and<script type="application/ld+json">blocks. The test asserts zero diagnostics are returned.biome_servicetests (98) andbiome_html_formattertests (127) pass.Checklist