'How to prevent Prettier from moving comments to new line

I have a typescript project formatted with prettier. My issue is when I save code like this:

const thing = await call({ // comment
  a: 1
});

Prettier moves the comment to a new line which is not what I want.

const thing = await call({
  // comment
  a: 1
});

How do I prevent this from happening while retaining all other format settings?

EDIT: I do not want to use another formatter or // prettier-ignore. I need this done from the config file .prettierrc.json



Solution 1:[1]

In my experience, you can specify certain areas of your code for prettier to ignore in the .prettierignore which uses the same syntax as a .gitignore. You can also ignore specific comments as this section of their documentation.

Solution 2:[2]

I'm pretty sure there is no way to configure this in .prettierrc, as prettier is opinionated. Though this kind of moving of comments to new line only happens when it appears beside opening brackets. If it really annoys you, you could change to a different linter, such as eslint, which to my knowledge does not do the above.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 letqin
Solution 2 Kenneth Lew