Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task done
standard-software opened this issue Jul 5, 2024 · 4 comments · Fixed by #3534
Closed
1 task done

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

standard-software opened this issue Jul 5, 2024 · 4 comments · Fixed by #3534
Assignees
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@standard-software
Copy link

standard-software commented Jul 5, 2024

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

  • I agree to follow Biome's Code of Conduct
@ematipico ematipico added A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Jul 5, 2024
@satojin219
Copy link
Contributor

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
Copy link
Author

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
Copy link
Contributor

<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
Copy link
Contributor

@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 >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Formatter Area: formatter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
3 participants