Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

feat(rome_json_formatter): Fallback to Verbatim for nodes with syntax errors #4066

Merged
merged 1 commit into from
Dec 19, 2022

Conversation

MichaReiser
Copy link
Contributor

Summary

Some prettier tests for JSON5 are failing after implementing array formatting in #4064

The tests fail because the formatting returns a FormatError::SyntaxError if a mandatory child node is missing but the error is never handled by the JSON formatting.

This PR fixes this by

  • Gracefully handle missing values on the root value by calling into verbatim formatting if that's the case
  • Use format_or_verbatim when formatting values

I had to pull out the format_or_verbatim from the rome_js_formatter and move it to rome_formatter so that it can be re-used between js and json formatting.

Test Plan

I added new tests for an empty file and a file with missing object property values.

Documentation

  • The PR requires documentation
  • I will create a new PR to update the documentation

@MichaReiser MichaReiser added A-Formatter Area: formatter L-JSON Language: JSON labels Dec 17, 2022
@netlify
Copy link

netlify bot commented Dec 17, 2022

Deploy Preview for docs-rometools canceled.

Name Link
🔨 Latest commit 4b19191
🔍 Latest deploy log https://app.netlify.com/sites/docs-rometools/deploys/639daee98cf37d0009109463

… errors

Some prettier tests for JSON5 are failing after implementing array formatting in #4064

The tests fail because the formatting returns a `FormatError::SyntaxError` if a mandatory child node is missing but the error is never handled by the JSON formatting.

This PR fixes this by

* Gracefully handle missing values on the root value by calling into verbatim formatting if that's the case
* Use `format_or_verbatim` when formatting values

I had to pull out the `format_or_verbatim` from the `rome_js_formatter` and move it to `rome_formatter` so that it can be re-used between js and json formatting.
@ematipico ematipico merged commit 2f82609 into main Dec 19, 2022
@ematipico ematipico deleted the feat/json-format-or-verbatim branch December 19, 2022 08:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Formatter Area: formatter L-JSON Language: JSON
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants