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

📝 Inconsistency between Prettier and Biome when formatting package.json #4299

Closed
1 task done
alissonlauffer opened this issue Oct 14, 2024 · 6 comments
Closed
1 task done
Labels
A-Formatter Area: formatter L-JSON Language: JSON and super languages

Comments

@alissonlauffer
Copy link

Environment information

CLI:
  Version:                      1.9.3
  Color support:                true

Platform:
  CPU Architecture:             x86_64
  OS:                           linux

Environment:
  BIOME_LOG_PATH:               unset
  BIOME_LOG_PREFIX_NAME:        unset
  BIOME_CONFIG_PATH:            unset
  NO_COLOR:                     unset
  TERM:                         "xterm-256color"
  JS_RUNTIME_VERSION:           "v22.9.0"
  JS_RUNTIME_NAME:              "node"
  NODE_PACKAGE_MANAGER:         "bun/1.1.30"

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:                 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:                      true
  Indent style:                 unset
  Indent width:                 unset
  Line ending:                  unset
  Line width:                   unset
  Trailing Commas:              unset

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:               0

Configuration

{
	"$schema": "./node_modules/@biomejs/biome/configuration_schema.json",
	"organizeImports": {
		"enabled": true
	},
	"linter": {
		"enabled": true,
		"rules": {
			"recommended": true
		}
	}
}

Playground link

https://github.com/alissonlauffer/biome-repro-1728945668010

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@alissonlauffer alissonlauffer added the S-Needs triage Status: this issue needs to be triaged label Oct 14, 2024
@alissonlauffer
Copy link
Author

It seems that Prettier actually creates a special case for package.json and expands all JSON lists only there by default. Other JSON files are handled in the same way as Biome currently handles all JSON files (collapsing them unless the line length exceeds the limit):

// bunx prettier package.json
{
  "name": "biome-repro",
  "version": "0.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "format": "biome format .",
    "lint": "biome lint",
    "check": "biome check",
    "ci": "biome ci"
  },
  "devDependencies": {
    "@biomejs/biome": "1.9.3"
  },
  "anyKey": [
    "foo",
    "bar"
  ]
}
// bunx prettier anyother.json
{
  "name": "biome-repro",
  "version": "0.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "format": "biome format .",
    "lint": "biome lint",
    "check": "biome check",
    "ci": "biome ci"
  },
  "devDependencies": {
    "@biomejs/biome": "1.9.3"
  },
  "anyKey": ["foo", "bar"]
}

@dyc3
Copy link
Contributor

dyc3 commented Oct 15, 2024

Yup. Prettier makes this exception so it's output aligns with what is output from package managers like npm and yarn.

@dyc3 dyc3 added A-Formatter Area: formatter L-JSON Language: JSON and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug labels Oct 15, 2024
@github-actions github-actions bot removed the S-Needs triage Status: this issue needs to be triaged label Oct 15, 2024
@alissonlauffer
Copy link
Author

alissonlauffer commented Oct 20, 2024

Now looking at the v2.0 roadmap, it seems that this was already added there 3 days before my issue 😅 (as "Format package.json with lineWidth: 1?" and "Format package.json like Prettier does, by default"). So maybe it could be linked to this issue here, since it had no linked issue.

@ematipico
Copy link
Member

The current issue isn't a bug. Biome formats the JSON file as expected.

Creating an option and applying it to the package would be a breaking change nonetheless. We will keep that issue open.

@ematipico ematipico removed the S-Bug-confirmed Status: report has been confirmed as a valid bug label Oct 20, 2024
@Conaclos
Copy link
Member

Conaclos commented Oct 21, 2024

Now looking at the v2.0 roadmap, it seems that this was already added there 3 days before my issue

I added it one week ago. We should take care of still allowing users to set formatting options for package.json in overrides. In fact, we could encode the package.json default formatting as the first overrides. This allows user overrides to override this one.

Sometimes I wonder why expanding array/object is not the default for JSON... However, I think we should keep the same defaults as Prettier.

@ematipico
Copy link
Member

I added it one week ago. We should take care of still allowing users to set formatting options for package.json in overrides. In fact, we could encode the package.json default formatting as the first overrides. This allows user overrides to override this one.

That's a great solution! I am going to close this issue. I opened this one #4370

@ematipico ematipico closed this as not planned Won't fix, can't repro, duplicate, stale Oct 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-JSON Language: JSON and super languages
Projects
None yet
Development

No branches or pull requests

4 participants