question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[JSON] Trailing comments are not handled

See original GitHub issue

We use the js expression parser (which shares the same printer with JSON) to parse binding syntax in HTML, but the trailing comments are removed (reported by https://github.com/prettier/prettier/pull/5259#issuecomment-429571079).

Prettier 1.14.3 Playground link

--parser json

Input:

index /* TODO: use id when links will be provided by API */

Output:

Error: Comment "TODO: use id when links will be provided by API" was not printed. Please report this error!
    at https://prettier.io/lib/standalone.js:10671:13
    at Array.forEach (<anonymous>)
    at ensureAllCommentsPrinted (https://prettier.io/lib/standalone.js:10669:15)
    at coreFormat (https://prettier.io/lib/standalone.js:10719:3)
    at format (https://prettier.io/lib/standalone.js:10874:16)
    at formatWithCursor (https://prettier.io/lib/standalone.js:10886:12)
    at https://prettier.io/lib/standalone.js:21134:15
    at Object.format (https://prettier.io/lib/standalone.js:21142:12)
    at formatCode (https://prettier.io/worker.js:188:21)
    at handleMessage (https://prettier.io/worker.js:139:18)

Expected behavior: Comments are printed.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ikatyangcommented, Oct 31, 2018

@michaeljota It’s indeed a vue-only issue after we switch to use angular-estree-parser for angular expression.

(Angular only allows a single-line comment at the end of the expression, excluding microsyntax.)

1reaction
renatoagdscommented, Oct 31, 2018

@ikatyang hey! I didn’t start it. go ahead 🤘

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can you use a trailing comma in a JSON object?
No. The JSON spec, as maintained at http://json.org, does not allow trailing commas. From ...
Read more >
Allow JSON with trailing commas #5708 - GitHub
I'm looking for a way to support the following style: JSON-based; Always quote keys; Always include trailing commas.
Read more >
JSON with Commas and Comments - Hacker News
As JSON is based on JavaScript's syntax prior to ES5, trailing commas are not allowed in JSON. json was largely `eval`d when it...
Read more >
How to allow some kinds of invalid JSON with System.Text.Json
By default, comments and trailing commas are not allowed in JSON. To allow comments in the JSON, set the JsonSerializerOptions.
Read more >
Why JSON doesn't support comments (Douglas Crockford)
Then you get not only comments, but also lots of other syntax niceties ... The lack of support for trailing commas and the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found