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
14.91k stars 463 forks source link

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

Open alissonlauffer opened 1 day ago

alissonlauffer commented 1 day ago

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

alissonlauffer commented 1 day ago

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 commented 1 day ago

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