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.

[TypeScript]: Comment is not printed ("Please report this error!")

See original GitHub issue

Prettier 1.19.1 Playground link

--parser babel

Input:

const a: T</* comment*/> = 1;

Output:

Error: Comment "comment" was not printed. Please report this error!
    at https://prettier.io/lib/standalone.js:15543:15
    at Array.forEach (<anonymous>)
    at ensureAllCommentsPrinted (https://prettier.io/lib/standalone.js:15541:17)
    at coreFormat (https://prettier.io/lib/standalone.js:15592:5)
    at format (https://prettier.io/lib/standalone.js:15832:75)
    at formatWithCursor (https://prettier.io/lib/standalone.js:15848:14)
    at https://prettier.io/lib/standalone.js:31794:17
    at Object.format (https://prettier.io/lib/standalone.js:31802:14)
    at formatCode (https://prettier.io/worker.js:234:21)
    at handleMessage (https://prettier.io/worker.js:185:18)

Expected behavior:

It to not error, and to print the comment.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Skalmancommented, Feb 16, 2020

@thorn0, I had assumed that this was the policy of Prettier, since Prettier does not format code with syntax errors.

Sorry for derailing the discussion. 😄

1reaction
G-Rathcommented, Feb 15, 2020

@Skalman I would say so - typically two bugs are less likely than one 😉

TS will parse and deal with anything,

True, which is because its robust and why prettier hasn’t dropped it in favor of babel 🙂

Generally, it’s better for user experience to be as robust and supporting as possible; while it wouldn’t be “wrong” to have prettier error, in doing so it means that a file with this code can never be formatted by prettier.

That’s actually one of the differences between eslint & typescript: eslint takes the erroring route bailing out at the first non-spec compliant or syntactically invalid character it runs into - the result is that ESLint just won’t lint your files if they have such code in them.

Meanwhile TypeScript strives to try and tell you as much about your code as possible, and so presses on when it encouters code that would make eslint error.

Neither is right or wrong - they’re serving different purposes, but I think for prettier in cases like these where the price of adding support is relatively cheap, it’s worth accepting them as a bug in prettier rather than hard failing 🙂


The above is mostly IMO - I don’t speak for the prettier team, nor the eslint or typescript teams, but thats what I feel gives the best UX 🤷‍♂

Read more comments on GitHub >

github_iconTop Results From Across the Web

API - ESBuild
This API call is used by the command-line interface if no input files are provided and the --bundle flag is not present. In...
Read more >
Code Inspections in JavaScript and TypeScript - JetBrains
Reports a function call that returns a Promise that is not used later. Such calls are usually unintended and indicate an error.
Read more >
Command Line Interface - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
How can I preserve comments in my custom Prettier plugin?
Right now all I get are "Comment xyz was not printed. Please report this error!" exceptions. The call order I've been running through:...
Read more >
HTML Comments - W3Schools
HTML Comment Tag · Add Comments · Hide Content · Hide Inline Content · HTML Exercises · Test Yourself With Exercises · Exercise:...
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