biomejs / biome

A toolchain for web projects, aimed to provide functionalities to maintain them. Biome offers formatter and linter, usable via CLI and LSP.
https://biomejs.dev
Apache License 2.0
13.93k stars 421 forks source link

📝 "Bracket Same Line" and comment mis format #3354

Closed standard-software closed 1 month ago

standard-software commented 2 months ago

Environment information

I am not good at English. Excuse me.

"Bracket Same Line = true"

`
<div
  sx={{
    position: 'absolute'
  }}
  // comment
>
  test
</div>

-> ``

<div
    sx={{
        position: "absolute",
    }}>
    // comment
    test
</div>;

This is a miss-formatting of the text inside the div, which has been changed.

Configuration

No response

Playground link

https://biomejs.dev/playground/?bracketSameLine=true&code=CgA8AGQAaQB2AAoAIAAgAHMAeAA9AHsAewAKACAAIAAgACAAcABvAHMAaQB0AGkAbwBuADoAIAAnAGEAYgBzAG8AbAB1AHQAZQAnAAoAIAAgAH0AfQAKACAAIAAvAC8AIABjAG8AbQBtAGUAbgB0AAoAPgAKACAAIAB0AGUAcwB0AAoAPAAvAGQAaQB2AD4ACgA%3D

Code of Conduct

satojin219 commented 1 month ago

I suggest converting // comments to / / comments to address this issue. This change can help maintain consistency in the codebase and might resolve some formatting problems associated with single-line comments.

Alternatively, it might be beneficial to introduce an error message when Bracket Same Line is set to true and a comment is placed before the >. This error message prompt users to convert the comment to a /* / style.

Best regards,

standard-software commented 1 month ago

If you try the playground, you will see that the same problem occurs with both // and / /.

The problem is immediately apparent when you run it in the playground: prettier has no problem, and biome has a problem. (Thank goodness playground exists!).

satojin219 commented 1 month ago
<div
  sx={{
    position: 'absolute'
  }}
  // comment >
  test
</div>

<div
  sx={{
    position: 'absolute'
  }} /* comment */ >
  test
</div>

I apologize if my explanation wasn't clear. Please look at the code above. The code above is a hypothetical example of how the formatting should work correctly. If 'Bracket Same Line' is true, the >should come after the comment. However, when the comment is //, the >would be commented out. Therefore, I thought it might be necessary to change the comment style to /* */. Alternatively, should we avoid format when there's a comment immediately before the>? Please share opinion on this.

satojin219 commented 1 month ago

@ematipico Might I take a shot at this? I'm considering implementing a solution to avoid formatting when there's a comment immediately before the >