Skip to content

📝 Formatter breaks TSX syntax with comment on first line of generic #5091

Description

@macarie

Environment information

CLI:
  Version:                      1.9.4
  Color support:                true

Platform:
  CPU Architecture:             aarch64
  OS:                           macos

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.12.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/9.15.5"

Biome Configuration:
  Status:                       Loaded successfully
  Formatter disabled:           false
  Linter disabled:              false
  Organize imports disabled:    false
  VCS disabled:                 false

Formatter:
  Format with errors:           false
  Indent style:                 Tab
  Indent width:                 2
  Line ending:                  Lf
  Line width:                   80
  Attribute position:           Auto
  Bracket spacing:              BracketSpacing(true)
  Ignore:                       []
  Include:                      []

JavaScript Formatter:
  Enabled:                      true
  JSX quote style:              Double
  Quote properties:             AsNeeded
  Trailing commas:              All
  Semicolons:                   Always
  Arrow parentheses:            Always
  Bracket spacing:              unset
  Bracket same line:            false
  Quote style:                  Double
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Attribute position:           unset

JSON Formatter:
  Enabled:                      false
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              None

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

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

Workspace:
  Open Documents:               0

Configuration

{
	"formatter": {
		"enabled": true
	},
}

Playground link

https://biomejs.dev/playground/?code=dAB5AHAAZQAgAEcAZQBuAGUAcgBpAGMAPABUAD4AIAA9ACAAVAAKAAoAZABlAGMAbABhAHIAZQAgAGMAbwBuAHMAdAAgAE4AYQBtAGUAcwBwAGEAYwBlADoAIAB7AAoACQBDAG8AbQBwAG8AbgBlAG4AdAA6ACAARwBlAG4AZQByAGkAYwA8AAoACQAJAC8ALwAgAGEAIABjAG8AbQBtAGUAbgB0AAoACQAJAHsACgAJAAkACQBjAGgAaQBsAGQAcgBlAG4AOgAgAHUAbgBrAG4AbwB3AG4AOwAKAAkACQB9AAoACQA%2BADsACgB9AAoA

Code of Conduct

  • I agree to follow Biome's Code of Conduct

Activity

  1. macarie commented on Feb 11, 2025

    @macarie
    Author

    It looks like this is a bug in Prettier as well.

    The generated code is valid TypeScript when JSX is disabled, but becomes invalid when JSX is enabled:

    I’m not sure what the best solution for this would be; maybe keeping the new line if JSX syntax is enabled?

  2. added
    L-JavaScriptLanguage: JavaScript and super languages
    S-Bug-confirmedStatus: report has been confirmed as a valid bug
    on Feb 11, 2025
  3. added
    S-Needs triageStatus: this issue needs to be triaged
    and removed
    S-Bug-confirmedStatus: report has been confirmed as a valid bug
    on Feb 11, 2025
  4. dyc3 commented on Feb 11, 2025

    @dyc3
    Contributor

    The code works if there is any whitespace between the < and the //. It's the <// part that is messing up the typescript parser. Are we sure that this isn't a typescript bug?

  5. macarie commented on Feb 11, 2025

    @macarie
    Author

    @dyc3 it's been an error in TS since "forever" (at least since 3.3) as far as I can tell. The code also works if the comment uses /* ... */, without requiring the extra whitespace.

    Maybe this is a limitation of their grammar, similar to how const fn = <T>(x: T) => x is an error with JSX enabled.

    On a somehow related note, it looks like Prettier handles that case by adding a comma before > while Biome throws a parsing error when JSX is enabled (playground link). Otherwise, it's a perfect match.

    Should I open a bug for this or is it a known/won't fix issue?

  6. dyc3 commented on Feb 11, 2025

    @dyc3
    Contributor

    Hmm, yeah that case is quite ambiguous.

    I'm open to diverging from prettier here to add/keep whitespace between the < and // but I'm not entirely sure if I have the full context. I would double check with typescript first, because maybe it is a bug on their side, and if it gets fixed, we wouldn't necessarily need to do anything on our side.

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

    A-FormatterArea: formatterL-JavaScriptLanguage: JavaScript and super languagesS-Needs triageStatus: this issue needs to be triaged

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions