dprint / dprint-plugin-json

JSON code formatting plugin for dprint.
https://dprint.dev/plugins/json
MIT License
18 stars 5 forks source link

Formatting JSONC can lose comments yet still indicate success #24

Open mmuddasani opened 1 year ago

mmuddasani commented 1 year ago

Describe the bug

deno fmt can lose comments without any indication. Minimal reproducible examples (via deno fmt): here Additional details: https://github.com/denoland/deno_std/issues/3502#issuecomment-1738428869

Another way to reproduce:

dprint fmt --config <(echo '{"plugins": ["https://plugins.dprint.dev/json-0.17.4.wasm"]}')

dprint version: 0.41.0 dprint-plugin-json version: 0.17.4

Input Code

// before-value (context: top-level)
{
  // before-key (context: object spot 0)
  "k0"
  // after-key (context: object spot 0)
  :
  // before-value (context: object spot 0)
  "v0"
  // after-value (context: object spot 0)
  ,
  // before-key (context: object spot 1)
}
// after-value (context: top-level)

Expected Output

One of two options:

Actual Output

// before-value (context: top-level)
{
  // before-key (context: object spot 0)
  "k0": // before-value (context: object spot 0)
  "v0"
  // before-key (context: object spot 1)
}
// after-value (context: top-level)