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

📝 Output is different based on initial formatting of input #3766

Closed
1 task done
parnavh opened this issue Sep 2, 2024 · 4 comments · Fixed by #3780
Closed
1 task done

📝 Output is different based on initial formatting of input #3766

parnavh opened this issue Sep 2, 2024 · 4 comments · Fixed by #3780
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

@parnavh
Copy link

parnavh commented Sep 2, 2024

Environment information

CLI:
  Version:                      1.8.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_DIR:                unset
  NO_COLOR:                     unset
  TERM:                         "foot"
  JS_RUNTIME_VERSION:           "v20.15.1"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "pnpm/9.5.0"

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

Formatter:
  Format with errors:           false
  Indent style:                 Space
  Indent width:                 2
  Line ending:                  Lf
  Line width:                   80
  Attribute position:           Auto
  Ignore:                       []
  Include:                      []

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

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

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

Workspace:
  Open Documents:               0

Configuration

{
  "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json",
  "organizeImports": {
    "enabled": true
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true
    }
  },
  "formatter": {
    "indentStyle": "space"
  }
}

Playground link

original
refined thanks @suxin2017!

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@parnavh
Copy link
Author

parnavh commented Sep 2, 2024

As seen in the playground, prettier gives consistent results with both of the functions with different initial formatting, but biome has 2 different outputs. Shouldn't this be the same? since the output should always be consistent after formatting.

Also while locally testing, in some cases if I formatted the code more than once repeatedly, the output would change. i.e the line in the playground:

return `Lectures: ${doneCount}/${totalCount} | Mins: ${(
		doneSecs / 60
	).toFixed(2)}/${(totalSecs / 60).toFixed(2)}| Hours: ${(
		doneSecs / 3600
	).toFixed(2)}/${(totalSecs / 3600).toFixed(2)}`;

would become

return `Lectures: ${doneCount}/${totalCount} | Mins: ${(
		doneSecs / 60
	).toFixed(2)}/${(totalSecs / 60).toFixed(2)}| Hours: ${(doneSecs / 3600).toFixed(2)}/${(totalSecs / 3600).toFixed(2)}`;

and then

return `Lectures: ${doneCount}/${totalCount} | Mins: ${(doneSecs / 60).toFixed(2)}/${(totalSecs / 60).toFixed(2)}| Hours: ${(doneSecs / 3600).toFixed(2)}/${(totalSecs / 3600).toFixed(2)}`;

@Conaclos Conaclos 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 Sep 3, 2024
@suxin2017
Copy link
Contributor

This problem is caused by the line width configuration. When the two sides are configured to 120, the behive of the two sides is consistent, and when the two sides are configured to 1000, they start to differ. biome Max line width = 320 will use the default 80 when it is greater than 320 and all the configurations will use the default configuration (for example, semicolons always configuration will also be broken), so the difference is caused

The following link sets line-wdth=322, which breaks the always configuration for semicolons
https://biomejs.dev/playground/?lineWidth=322&indentStyle=space&quoteProperties=preserve&code=YwBvAG4AcwB0ACAAYQA9ACAAIABgAEwAZQBjAHQAdQByAGUAcwA6ACAAJAB7AGQAbwBuAGUAQwBvAHUAbgB0AH0ALwAkAHsAdABvAHQAYQBsAEMAbwB1AG4AdAB9ACAAfAAgAE0AaQBuAHMAOgAgACQAewAoAGQAbwBuAGUAUwBlAGMAcwAgAC8AIAA2ADAAKQAuAHQAbwBGAGkAeABlAGQAKAAKACAAIAAgACAAMgAsAAoAIAAgACkAfQAvACQAewAoAHQAbwB0AGEAbABTAGUAYwBzACAALwAgADYAMAApAC4AdABvAEYAaQB4AGUAZAAoAAoAIAAgACAAIAAyACwACgAgACAAKQB9AHwAIABIAG8AdQByAHMAOgAgACQAewAoAGQAbwBuAGUAUwBlAGMAcwAgAC8AIAAzADYAMAAwACkALgB0AG8ARgBpAHgAZQBkACgACgAgACAAIAAgADIALAAKACAAIAApAH0ALwAkAHsAKAB0AG8AdABhAGwAUwBlAGMAcwAgAC8AIAAzADYAMAAwACkALgB0AG8ARgBpAHgAZQBkACgACgAgACAAIAAgADIALAAKACAAIAApAH0AYAA7AAoACgBjAG8AbgBzAHQAIABiACAAPQAgAGAATABlAGMAdAB1AHIAZQBzADoAIAAkAHsAZABvAG4AZQBDAG8AdQBuAHQAfQAvACQAewB0AG8AdABhAGwAQwBvAHUAbgB0AH0AIAB8ACAATQBpAG4AcwA6ACAAJAB7ACgAZABvAG4AZQBTAGUAYwBzACAALwAgADYAMAApAC4AdABvAEYAaQB4AGUAZAAoADIAKQB9AC8AJAB7ACgAdABvAHQAYQBsAFMAZQBjAHMAIAAvACAANgAwACkALgB0AG8ARgBpAHgAZQBkACgAMgApAH0AfAAgAEgAbwB1AHIAcwA6ACAAJAB7ACgAZABvAG4AZQBTAGUAYwBzACAALwAgADMANgAwADAAKQAuAHQAbwBGAGkAeABlAGQAKAAyACkAfQAvACQAewAoAHQAbwB0AGEAbABTAGUAYwBzACAALwAgADMANgAwADAAKQAuAHQAbwBGAGkAeABlAGQAKAAyACkAfQBgADsACgAgAA%3D%3D

@parnavh
Copy link
Author

parnavh commented Sep 4, 2024

Hi!

The different I am talking about is between the different output of string a and b. I am not comparing with prettier, I am comparing the string a with string b when formatted by biome. The strings are the same, I just manually formatted string a in a different way than b which results in a different output. I see that even prettier has the same output as biome, but i believe if the strings are the same just with different whitespaces, the end result should be same.

Biome seems to agree with me since when I copy the output of the first iteration and format it again, it makes both string a and b the same, the only problem being that it violates the line width of 80 and places everything in a single line when the line can be broken down. Prettier does not change its output (the 2 strings are not formatted the same, but the number of runs does not change its output). This is weird now since the output also depends on how many times biome is run.

This might be a weird edge case and is problematic since now I have to be aware of the initial whitespace placement as well and if anything changes after multiple runs

@suxin2017
Copy link
Contributor

Thank you for your reply, I probably found the problem location, let me see how to fix it

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

Successfully merging a pull request may close this issue.

3 participants