Skip to content

📝 Astro comments aren't correctly recognized #8294

Description

@hexadecimal233

Environment information

CLI:
  Version:                      2.3.7
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           windows

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  BIOME_THREADS:                unset
  NO_COLOR:                     unset
  TERM:                         unset
  JS_RUNTIME_VERSION:           v24.4.1
  JS_RUNTIME_NAME:              node
  NODE_PACKAGE_MANAGER:         unset

Biome Configuration:
  Status:                       Loaded successfully
  Path:                         biome.json
  Formatter enabled:            true
  Linter enabled:               true
  Assist enabled:               true
  VCS enabled:                  true

Formatter:
  Format with errors:           unset
  Indent style:                 Space
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   100
  Attribute position:           unset
  Bracket spacing:              unset
  Includes:                     unset

JavaScript Formatter:
  Enabled:                      unset
  JSX quote style:              unset
  Quote properties:             unset
  Trailing commas:              unset
  Semicolons:                   As needed
  Arrow parentheses:            unset
  Bracket spacing:              unset
  Bracket same line:            true
  Quote style:                  Double Quotes
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Attribute position:           unset

JSON Formatter:
  Enabled:                      unset
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              unset
  Expand lists:                 unset

CSS Formatter:
  Enabled:                      unset
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Quote style:                  unset

GraphQL Formatter:
  Enabled:                      unset
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Bracket spacing:              unset
  Quote style:                  unset

Workspace:
  Open Documents:               0

Configuration

Playground link

https://biomejs.dev/playground/?code=PABkAGkAdgA%2BAAoAIAAgAHsALwAqACAAQwBvAG0AbQBlAG4AdAAgADEAIAAqAC8AfQAKACAAIAB7AC8AKgAgAEMAbwBtAG0AZQBuAHQAIAAyACAAKgAvAH0ACgA8AC8AZABpAHYAPgA%3D&language=astro

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Activity

  1. added
    S-EnhancementStatus: Improve an existing feature
    S-Has workaroundStatus: has a workaround, so users can still work with the bug
    L-HTMLLanguage: HTML and super languages
    on Nov 27, 2025
  2. ematipico commented on Nov 27, 2025

    @ematipico
    Member

    That's an unfortunate thing about Astro. I'm not very keen on supporting two types of comments. As for now, I'd say we should focus on HTML comments

  3. changed the issue type fromtoon Nov 27, 2025
  4. dhruvkb commented on Dec 1, 2025

    @dhruvkb

    The behaviours of the two different kinds of comments are different. HTML style comments <!-- ... --> are present in the DOM but JS style comments {/* ... */} are not. It would be really nice if they could be supported (or at the very least, recognised as valid syntax).

  5. ematipico commented on Dec 1, 2025

    @ematipico
    Member

    I don't understand why you talk about behaviour, comments are comments, they have the same semantics; and I know about the two kinds of comments: when inside an expression, Astro switches to JSX-like syntax.

    The huge hole is that there's no rule or standard when it comes to comments inside an expression

    {items => (
      <li>
        Which comments can we use here?
      </li>
    )}
    

    You might answer both, but then we aren't parsing JSX-like anymore, but something else, which doesn't have a standard even in the Astro website.

  6. dyc3 commented on Dec 2, 2025

    @dyc3
    Contributor

    @ematipico On the page that he linked it says:

    HTML-style comments will be included in browser DOM, while JS ones will be skipped.

    Which means that the two comment styles have different behavior.

    Regarding comments inside expressions like that, for the duration of the embedded expression we have to switch to the javascript parser (which also could be jsx enabled), where html comments <!-- foo --> are invalid, and /* foo */ is valid. It's not standardized, but that's how the tools behave (at least some of them).

  7. ematipico commented on Dec 2, 2025

    @ematipico
    Member

    But we don't do any transformation, so whether the Astro compiler decides to remove them or not, it doesn't concern us because, and a suppression comment of Biome could be used both ways.

    Am I missing something?

  8. dyc3 commented on Dec 4, 2025

    @dyc3
    Contributor

    If we don't treat it like trivia, then suppression comments won't work at all. Do we have tests for it yet? I don't recall seeing any during reviews.

  9. ematipico commented on Dec 4, 2025

    @ematipico
    Member

    No we don't have tests, and we don't parse them yet.

  10. cworld1 commented on Dec 24, 2025

    @cworld1

    I need this also. Is there any method to temporary disable this error msg?

  11. Boston343 commented on Jan 26, 2026

    @Boston343

    Potential related issue I just came across trying this out in an astro project related to multi-line comments in the astro frontmatter.

    If you have a multi line comment like the below, then the rest of the file will show a bunch of errors:

    ---
    /**
     * In this comment, if you add any string opening or closing, such as an apostrophy, the file will show 
     * a bunch of errors. Doesn't (remove the apostrophy in the previous word to fix) that stink? 
     */
    import type { HTMLAttributes } from "astro/types";
    
    type Props = HTMLAttributes<"div">;
    
    const { class: className, ...rest } = Astro.props;
    ---
    
    <div
      class="some-classes"
      data-state="closed"
      style="animation: none;"
      data-slot="accordion-content"
      {...rest}
    >
      <div class="pt-0 pb-4">
        <slot />
      </div>
    </div>
    

    playground demo

  12. dyc3 commented on Jan 26, 2026

    @dyc3
    Contributor

    @Boston343 That sounds like a different issue. Can you file a new issue for it?

  13. tomkel commented on Feb 17, 2026

    @tomkel

    I'm using JS-style comments in Astro, in order to control eslint like so:

    </div></div> {/* eslint-disable-line @stylistic/jsx-closing-tag-location, @stylistic/indent */}

    It's a parsing error in biome.

    The astro docs present a valid use case: for comments that you want removed from the final build.

  14. astrochemx commented on Feb 20, 2026

    @astrochemx

    Starting in Biome 2.4.0, Astro files fail to parse when a template expression block is empty ( { } ) or contains only a comment ( { /* comment */ } ). The parser throws the error: Expected a valid expression in template syntax. This suggests the parser no longer considers a comment to be a valid inhabitant of a template expression block. This was working correctly in 2.3.15 and earlier versions, so this appears to be a regression.

    My use case:

    {
      // eslint-disable-next-line better-tailwindcss/no-unknown-classes
    }<div class="unknown">
      <p>Text</p>
    </div>
    
    Example Biome Output
    components\Component.astro:3:1 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    
      × Expected a valid expression in template syntax
    
        1 │ {
        2 │   // eslint-disable-next-line better-tailwindcss/no-unknown-classes
      > 3 │ }<div class="unknown">
          │
        4 │   <p>Text</p>
        5 │ </div>
    
      i Template expressions can only contain JavaScript expressions, not statements like 'let', 'if', or 'function'.
    
    Temporary Workaround

    For those affected by this regression, you can bypass the parse error by moving the comment/suppression inside a dynamic attribute expression. This satisfies the parser's requirement for a "valid expression" while still keeping the comment on the relevant line:

    <div class={'unknown' /* eslint-disable-line better-tailwindcss/no-unknown-classes */}>
      <p>Text</p>
    </div>
    

    Playground Link

    UPD. Created a separate issue #9165.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    L-HTMLLanguage: HTML and super languagesS-EnhancementStatus: Improve an existing featureS-Has workaroundStatus: has a workaround, so users can still work with the bug

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions