Skip to content

feat(formatter_json): Implement oxc_formatter_json (json variant only)#22641

Merged
graphite-app[bot] merged 1 commit into
mainfrom
05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_
May 29, 2026
Merged

feat(formatter_json): Implement oxc_formatter_json (json variant only)#22641
graphite-app[bot] merged 1 commit into
mainfrom
05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_

Conversation

@leaysgur

@leaysgur leaysgur commented May 21, 2026

Copy link
Copy Markdown
Member

Part of #19704

In Prettier, there are 4 variants for JSON formatting.

  • json 👈🏻 this
  • jsonc
  • json5
  • json-stringify

Although Prettier calls "JSON", it doesn't strictly adhere to the JSON specification; in practice, it behaves more like JS...

To begin with, it uses babel.parseExpression(), which makes the input parsing very lenient. The output also doesn't necessarily conform to the specification—for instance, it allows comments and sometimes omits double quotes on keys.

Because of this, we are re-implementing it using oxc_parser. Since parse_expression() cannot capture comments, I've achieved this by wrapping the input in ().

Also considered adding JSON support to oxc_formatter, but I have decided NOT to for now. We may reconsider this once we have bothered on various edge cases.

leaysgur commented May 21, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from 9e17379 to da9b4e4 Compare May 21, 2026 09:16
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from c23d02a to 1f02f0a Compare May 21, 2026 09:16
@leaysgur leaysgur changed the title feat(formatter_json): Implement oxc_formatter_json (json variant only) feat(formatter_json): Implement oxc_formatter_json (json variant only) May 21, 2026
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch 2 times, most recently from 52614ae to c5936f1 Compare May 21, 2026 09:21
@codspeed-hq

codspeed-hq Bot commented May 21, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 57 untouched benchmarks


Comparing 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ (4bff424) with 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core (15bef1e)

Open in CodSpeed

@camc314 camc314 added the A-formatter Area - Formatter label May 21, 2026
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from c5936f1 to a7a5480 Compare May 22, 2026 00:31
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from da9b4e4 to efa1e46 Compare May 22, 2026 00:31
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch 5 times, most recently from 9d3324e to eb658cf Compare May 22, 2026 03:21
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from efa1e46 to 6cdd132 Compare May 22, 2026 03:21
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from eb658cf to 5724334 Compare May 22, 2026 03:50
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from 6cdd132 to fd0a1f5 Compare May 22, 2026 03:50
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch 2 times, most recently from f17381b to e297be2 Compare May 22, 2026 06:39
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from fd0a1f5 to edff188 Compare May 22, 2026 06:39
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from e297be2 to 1d61bc2 Compare May 22, 2026 08:12
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from b0d364e to 6b2a53d Compare May 22, 2026 08:14
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from edff188 to d194f75 Compare May 25, 2026 00:38
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch 2 times, most recently from 67e4127 to cd27ff4 Compare May 25, 2026 02:10
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from d194f75 to 87b4092 Compare May 25, 2026 02:10
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from 6be3e1c to 709d91e Compare May 25, 2026 11:25
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch 2 times, most recently from b918c86 to b3d5bbb Compare May 26, 2026 06:24
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from 709d91e to ac399ca Compare May 26, 2026 06:24
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from b3d5bbb to 7f3657c Compare May 26, 2026 08:21
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from ac399ca to 39d4551 Compare May 26, 2026 08:21
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from 7f3657c to 533b669 Compare May 28, 2026 00:44
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch 2 times, most recently from 0a57d19 to f1b2aef Compare May 28, 2026 02:33
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from 533b669 to 91950d8 Compare May 28, 2026 02:33
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from f1b2aef to dbfdc50 Compare May 28, 2026 06:46
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch 3 times, most recently from f572a5e to 792ee0a Compare May 28, 2026 07:29
@leaysgur leaysgur force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from dbfdc50 to 15bef1e Compare May 29, 2026 00:27
@leaysgur leaysgur force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from 792ee0a to 4bff424 Compare May 29, 2026 00:27
@leaysgur leaysgur marked this pull request as ready for review May 29, 2026 00:48
@graphite-app graphite-app Bot added the 0-merge Merge with Graphite Merge Queue label May 29, 2026
@graphite-app

graphite-app Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Merge activity

…ly) (#22641)

Part of #19704

In Prettier, there are 4 variants for JSON formatting.

- json 👈🏻 this
- jsonc
- json5
- json-stringify

Although Prettier calls "JSON", it doesn't strictly adhere to the JSON specification; in practice, it behaves more like JS...

To begin with, it uses `babel.parseExpression()`, which makes the input parsing very lenient. The output also doesn't necessarily conform to the specification—for instance, it allows comments and sometimes omits double quotes on keys.

Because of this, we are re-implementing it using `oxc_parser`. Since `parse_expression()` cannot capture comments, I've achieved this by wrapping the input in `()`.

Also considered adding JSON support to `oxc_formatter`, but I have decided NOT to for now. We may reconsider this once we have bothered on various edge cases.
@graphite-app graphite-app Bot force-pushed the 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core branch from 15bef1e to c323187 Compare May 29, 2026 00:49
@graphite-app graphite-app Bot force-pushed the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch from 4bff424 to 49db054 Compare May 29, 2026 00:50
Base automatically changed from 05-20-refactor_formatter_split_oxc_formatter_and_oxc_formatter_core to main May 29, 2026 00:56
@graphite-app graphite-app Bot removed the 0-merge Merge with Graphite Merge Queue label May 29, 2026
@graphite-app graphite-app Bot merged commit 49db054 into main May 29, 2026
32 checks passed
@graphite-app graphite-app Bot deleted the 05-21-feat_formatter_json_implement_oxc_formatter_json_json_variant_only_ branch May 29, 2026 00:57
camc314 pushed a commit that referenced this pull request Jun 1, 2026
# Oxlint
### 🚀 Features

- e4b1f46 linter/typescript: Implement `method-signature-style` rule
(#22679) (Mikhail Baev)
- bc462ca linter/vue: Implement no-reserved-component-names rule
(#22741) (bab)
- ef9e751 linter/vue: Implement component-definition-name-casing rule
(#22818) (bab)
- d67f51a linter/vue: Implement require-prop-type-constructor rule
(#22708) (bab)
- 1444f82 linter/promise/spec-only: Add `Promise.try` to `Promise`
static methods (#22812) (Ben Saufley)
- 8422e8b linter/jsdoc: Implement `require-yields-description` rule
(#22805) (Mikhail Baev)
- fe93f97 linter/eslint: Implement `prefer-named-capture-group` rule
(#22759) (Sebastian Poxhofer)
- 1a7798b linter: Add suggestion for `unicorn/no-new-array` (#22682)
(Sysix)

### 🐛 Bug Fixes

- 760a9f9 linter: Report errors when writing to the filesystem (#22881)
(camc314)
- e5a2748 linter: Avoid no-unreachable false positive after conditional
loop (#22869) (camc314)
- 39d92d6 linter/arrow-body-style: Preserve comments within function
(#22854) (Sysix)
- 3d13e29 parser: Reject `declare` in an already-ambient context
(TS1038) (#22850) (Boshen)
- 5152854 parser: Reject statements in ambient contexts (TS1036)
(#22849) (Boshen)
- 2eafea6 parser: Reject function implementations in ambient contexts
(TS1183) (#22845) (Boshen)
- c645615 parser: Reject incompatible class member modifiers (#22843)
(Boshen)
- 4a1ca4a linter/export: Detect duplicate explicit exports (#22798)
(camc314)
- 0a9a735 linter/no-loop-func: Allow safe let closures (#22811)
(camc314)
- 1599f11 linter: Align lsp extends default plugins (#22788) (camc314)
- db32ec9 linter/no-accumulating-spread: Use loop as primary span
(#22800) (camc314)
- 33ec6b4 linter/consistent-test-it: Avoid adjacent describe leakage
(#22796) (camc314)
- 2606069 linter/no-array-sort: Unwrap parenthesized sort args (#22794)
(camc314)
- 9f2f709 linter/no-array-sort: Skip non compare fn sort arguments
(#22752) (Gaurav Dubey)
- 27268a0 linter/no-else-return: Preserve statement boundary in fixer
(#22687) (camc314)
- d9cb6d8 linter/no-empty-function: Allow functions callbacks with
`allow: functions` (#22764) (camc314)
- a40a314 linter/no-shadow-restricted-names: Ignore enum members
(#22762) (camc314)
- 82366d9 linter/no-cond-assign: Align ternary handling (#22761)
(camc314)

### 📚 Documentation

- 5e113ba linter: Add license notices for ported ESLint plugins (#22768)
(Boshen)
# Oxfmt
### 🚀 Features

- d75cbbf oxfmt: Format `parser:json` files by `oxc_formatter_json`
(#22709) (leaysgur)
- 49db054 formatter_json: Implement `oxc_formatter_json` (json variant
only) (#22641) (leaysgur)
- 9c71f2e ast, codegen, formatter: Add `WithClauseKeyword::as_str`
helper and use it (#22791) (camc314)

### 🐛 Bug Fixes

- d3cdd62 oxfmt: Skip formatting for whitespace-only file (#22780)
(leaysgur)
- 23f0cc8 formatter: Don't move comments inside variable declaration in
for in loop (#22776) (leaysgur)
- f200c40 formatter: Don't move comments inside variable declaration in
for of loop (#22773) (Leonabcd123)

### 📚 Documentation

- 845f393 oxfmt,formatter,formatter_json,formatter_core: Add/update
AGENTS.md (#22873) (leaysgur)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-formatter Area - Formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants