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

📝 Line comment for case: statement is dissociated by unstable formatting #2786

Open
1 task done
lgarron opened this issue May 9, 2024 · 1 comment
Open
1 task done
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

@lgarron
Copy link

lgarron commented May 9, 2024

Environment information

Reproduces in playground (presumably v1.7.3).

Configuration

Default config.

Playground link

https://biomejs.dev/playground/?code=ZgB1AG4AYwB0AGkAbwBuACAAYwBvAG8AbAAoAHgAKQAgAHsACgAgACAAcwB3AGkAdABjAGgAIAAoAHgAKQAgAHsACgAgACAAIAAgAGMAYQBzAGUAIAA0ADoAIAAvAC8AIABnAHUAYQByAGEAbgB0AGUAZQBkACAAdABvACAAYgBlACAAcgBhAG4AZABvAG0ACgAgACAAIAAgAGMAYQBzAGUAIAA0ADIAOgAgAC8ALwAgAGMAbABhAHMAcwBpAGMACgAgACAAIAAgAGMAYQBzAGUAIAAxADMAMwA3ADoAIAAvAC8AIABFAEwASQBUAEUACgAgACAAIAAgAHsACgAgACAAIAAgACAAIABjAG8AbgBzAG8AbABlAC4AbABvAGcAKAAiAHgAIABpAHMAIABjAG8AbwBsACIAKQA7AAoAIAAgACAAIAAgACAAYgByAGUAYQBrADsACgAgACAAIAAgAH0ACgAgACAAIAAgAGQAZQBmAGEAdQBsAHQAOgAgAHsACgAgACAAIAAgACAAIABjAG8AbgBzAG8AbABlAC4AZQByAHIAbwByACgAIgB4ACAAaQBzACAAbgBvAHQAIABjAG8AbwBsACIAKQA7AAoAIAAgACAAIAB9AAoAIAAgAH0ACgB9AA%3D%3D

function cool(x) {
  switch (x) {
    case 4: // guaranteed to be random
    case 42: // classic
    case 1337: // ELITE
    {
      console.log("x is cool");
      break;
    }
    default: {
      console.error("x is not cool");
    }
  }
}

… is reformatted into:

// …
		case 42: // classic
		case 1337: { // ELITE
			console.log("x is cool");
// …

However, this is not stable. Running the formatter again produces:

// …
		case 42: // classic
		case 1337: {
			// ELITE
			console.log("x is cool");

// …

The comment now appears to refer to the contents of the case block rather than the case statement. I would suggest that the original formatting is preserved, else it becomes impossible to annotate the final case statement in a situation like this.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@lgarron lgarron changed the title 📝 Line comment for case: statement is dissociated by unstabled formatting 📝 Line comment for case: statement is dissociated by unstable formatting May 9, 2024
@Conaclos Conaclos added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels May 9, 2024
@Conaclos
Copy link
Member

Conaclos commented May 9, 2024

Biome has the same behavior as Prettier here, however I accept that it is an undesirable behavior since we got a formatting instability. Thanks for reporting this!

@Conaclos Conaclos added A-Formatter Area: formatter and removed A-Linter Area: linter labels May 23, 2024
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
Development

No branches or pull requests

2 participants