Repository navigation
📝 Formatter breaks TSX syntax with comment on first line of generic #5091
Copy link
Copy link
Closed
Copy link
Labels
A-FormatterArea: formatterArea: formatterL-JavaScriptLanguage: JavaScript and super languagesLanguage: JavaScript and super languagesS-Needs triageStatus: this issue needs to be triagedStatus: this issue needs to be triaged
Description
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: 0Configuration
{
"formatter": {
"enabled": true
},
}Playground link
Code of Conduct
- I agree to follow Biome's Code of Conduct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-FormatterArea: formatterArea: formatterL-JavaScriptLanguage: JavaScript and super languagesLanguage: JavaScript and super languagesS-Needs triageStatus: this issue needs to be triagedStatus: this issue needs to be triaged
Activity
macarie commentedon Feb 11, 2025
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?
dyc3 commentedon Feb 11, 2025
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?macarie commentedon Feb 11, 2025
@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) => xis 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?
dyc3 commentedon Feb 11, 2025
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.Update dependency @biomejs/biome to v2.5.12 (#21)
Update dependency @biomejs/biome to v2.5.12 (#43)