Fix eslint-plugin-astro <script> parsing errors#787
Fix eslint-plugin-astro <script> parsing errors#787smnbbrv wants to merge 1 commit intoprettier:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 87e612b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (9)
✅ Files skipped from review due to trivial changes (6)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds Astro support to the toolchain by registering Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer (commit)
participant CI as Test Runner (test/prettier.mjs)
participant ESLint as eslint-plugin-astro
participant Prettier as Prettier
participant Worker as worker.mjs
Dev->>CI: push changes (configs, fixtures, deps)
CI->>ESLint: load flat/base config + astro overrides
CI->>Prettier: call getFileInfo for files
Prettier->>Worker: return inferredParser = "astro"
Worker->>Prettier: skip format (parserBlocklist contains "astro")
CI->>ESLint: lint .astro fixtures using eslint-plugin-astro rules
ESLint-->>CI: report diagnostics (prettier/prettier enforced for embedded scripts)
CI-->>Dev: test results
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Summary
Fix
eslint-plugin-prettierfailing on.astrofiles containing<script>blocksProblem
When using
eslint-plugin-prettierwitheslint-plugin-astro, linting.astrofiles with<script>blocks fails with:Related: ota-meshi/eslint-plugin-astro#132
Root cause
eslint-plugin-astroextracts<script>blocks as virtual.jsfiles (e.g.,Component.astro/1.js). Wheneslint-plugin-prettierprocesses these:prettier.getFileInfo()is called with the real.astropath, inferring"astro"as the parserparserBlocklistcheck"astro"was missing from the blocklist, so the plugin tried to format the bare JS/TS fragment withparser: "astro"ifblocks) and TypeScript syntax (interface,type, generics)This affects all
<script>variants: regular<script>,<script is:inline>,<script is:raw>, and<script define:vars={...}>.Fix
Add
'astro'to theparserBlocklist, matching the existing behavior forvue,svelte,html, etc. The extracted script blocks are skipped since prettier will format the full.astrofile anyway.Test plan
Added integration tests covering all four Astro script types:
Component.astro— regular<script>with TypeScript (interface,ascasts)Inline.astro—<script is:inline>with object literalsRaw.astro—<script is:raw>with function bodiesDefineVars.astro—<script define:vars={...}>withifblocksTests re-enable
prettier/prettieron the extracted virtual files (sinceeslint-plugin-astro'sflat/baseconfig disables it by default) to verify the blocklist is actually exercised. Removing'astro'from the blocklist causes all four fixtures to fail withParsing error: Unexpected token, expected "}".New dev dependencies
eslint-plugin-astro— provides the processor that extracts<script>blocks as virtual filesprettier-plugin-astro— required forprettier.getFileInfo()to infer"astro"as the parser for.astrofiles@typescript-eslint/parser— parses TypeScript in extracted virtual files so ESLint doesn't fail before the prettier rule runstypescript— peer dependency of@typescript-eslint/parserThank you for maintaining the plugin!
Summary by CodeRabbit
New Features
Tests
Chores