admin管理员组文章数量:1405412
I have my formatter installed, which is prettier, and I have enabled the format on save but I e across this problem which is sometimes it adds unnecessary new lines every time I save them, example in an array, like this:
const days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
]
const months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
]
Whereas before I saved, it just (and should be) look like this:
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
I was wondering what configuration should I make to prevent this change while still keeping the 'format on save' enabled.
I have my formatter installed, which is prettier, and I have enabled the format on save but I e across this problem which is sometimes it adds unnecessary new lines every time I save them, example in an array, like this:
const days = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
]
const months = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec',
]
Whereas before I saved, it just (and should be) look like this:
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
I was wondering what configuration should I make to prevent this change while still keeping the 'format on save' enabled.
Share Improve this question asked Feb 6, 2021 at 5:11 codiecub15codiecub15 511 gold badge2 silver badges6 bronze badges3 Answers
Reset to default 3https://prettier.io/docs/en/ignore.html
Try this, seems to align with what you are looking for. Posted the link to show how //prettier-ignore
can prevent this from happening on save.
This is one of the biggest problems with prettier and why we have stopped using it on most projects.
There is apparently no way to turn it off because "prettier is opinionated". Unfortunately, some of the choices made by the creators hurt readability more than they help. (As you have found out.) It would be fine if you could customize it per project but certain formatting rules cannot be controlled.
Try using something like js-beautify which is less opinionated and does not attempt to format every aspect of your code.
Try changing Print Width in Extension Settings https://i.sstatic/aHyif.png
本文标签: javascriptHow to stop prettier to keep adding new lines automaticallyStack Overflow
版权声明:本文标题:javascript - How to stop prettier to keep adding new lines automatically? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744285715a2598867.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论