Skip to content

fix(linter): skip linting astro scripts with non JS script types#21954

Open
camc314 wants to merge 1 commit intomainfrom
codex/fix-astro-script-type
Open

fix(linter): skip linting astro scripts with non JS script types#21954
camc314 wants to merge 1 commit intomainfrom
codex/fix-astro-script-type

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented Apr 29, 2026

fixes #21942

Astro script tags with non-JavaScript type values are now skipped by the partial loader, so import maps and JSON scripts are not parsed as TypeScript. The shared script attribute parser is reused with Svelte to avoid duplicating tag parsing logic.

@camc314 camc314 changed the title fix(linter): problem fix(linter): skip linting astro scripts with non JS scrtipt types Apr 29, 2026
@camc314 camc314 marked this pull request as ready for review April 29, 2026 17:16
Copilot AI review requested due to automatic review settings April 29, 2026 17:16
@camc314 camc314 self-assigned this Apr 29, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes incorrect linting/parsing of non-JavaScript <script> tags in .astro files (e.g., type="importmap"), and reduces duplicated tag-attribute parsing logic by reusing a shared attribute parser between Astro and Svelte partial loaders.

Changes:

  • Add shared <script> attribute parsing utilities (AttributeValue, find_attribute) to the partial loader module.
  • Refactor Svelte partial loader to reuse the shared attribute parser.
  • Update Astro partial loader to (a) use the robust closing-angle finder and (b) skip <script> blocks whose type is not a JavaScript type; add tests for the new behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
crates/oxc_linter/src/loader/partial_loader/svelte.rs Switches Svelte to reuse the shared <script> attribute parser (removes local duplicate implementation).
crates/oxc_linter/src/loader/partial_loader/mod.rs Introduces shared AttributeValue + find_attribute helpers for parsing <script> tag attributes.
crates/oxc_linter/src/loader/partial_loader/astro.rs Uses find_script_closing_angle, adds JS type filtering logic, and adds tests to ensure non-JS script types are skipped.

js_start = pointer;

// check for the / of a self closing script tag
if self.source_text.chars().nth(js_start - 2) == Some('/') {
AttributeValue::Empty
};

if name == target {
Comment on lines +120 to +131
fn is_javascript_script(content: &str) -> bool {
match find_attribute(content, "type") {
Some(AttributeValue::Empty) | None => true,
Some(AttributeValue::Value(value)) => matches!(
value.trim().to_ascii_lowercase().as_str(),
"" | "module"
| "text/javascript"
| "application/javascript"
| "text/ecmascript"
| "application/ecmascript"
),
}
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing codex/fix-astro-script-type (29b6499) with main (024c390)

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Sysix Sysix changed the title fix(linter): skip linting astro scripts with non JS scrtipt types fix(linter): skip linting astro scripts with non JS script types Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: importmap issue in Astro

2 participants