简体   繁体   English

为什么 prettier 开始拆分短线?

[英]Why prettier started splitting short lines?

I used prettier for Angular project in VSCode for a few months.我在 VSCode 的 Angular 项目中使用了 prettier 几个月。 It worked ok-ish.它工作正常。

Today I upgraded Angular to v11 and the moment I've started changing my ts file (in this case I was changing file with unit tests, extension.spec.ts) and one line which has 85 characters is being split from:今天我将 Angular 升级到 v11 并且当我开始更改我的 ts 文件时(在这种情况下我正在更改带有单元测试的文件,extension.spec.ts)并且有 85 个字符的一行被拆分为:

const tblRows = fixture.debugElement.nativeElement.querySelectorAll('table tr');

to

const tblRows =
      fixture.debugElement.nativeElement.querySelectorAll('table tr');

At the same time, a much longer line in the same file is not being split:同时,同一文件中更长的一行没有被拆分:

it('Loaded map descriptions should load names and set state for "Edit" buttons', () => {

I've started learning this more, found settings "print width", it was 80. I've changed it to 140, then to 120 - it does not make any visible difference.我已经开始更多地学习这个,找到设置“打印宽度”,它是 80。我已经将它更改为 140,然后更改为 120 - 它没有任何明显的区别。

在此处输入图像描述

I've checked another file, the line with 120 characters is not being split...我检查了另一个文件,120 个字符的行没有被拆分...

I've checked, prettier is used as a default formatted:我检查过,prettier 用作默认格式:

在此处输入图像描述

Please help to find the cause of this problem.请帮助查找此问题的原因。 Thanks!谢谢!

I still dunno why prettier stopped working, but today I figured out how to FORCE it working.我仍然不知道为什么 prettier 停止工作,但今天我想出了如何强制它工作。

TBH, it's shame I could not do it earlier, the only excuse I have is that there were lots of things to learn and I was just overwhelmed. TBH,很遗憾我不能早点做,我唯一的借口是有很多东西要学,我只是不知所措。

Anyway, today I gave it another try and googled on "vscode prettier how to define line length", which led me to https://prettier.io/docs/en/options.html .不管怎样,今天我又试了一次,用谷歌搜索“vscode prettier 如何定义行长度”,这让我找到了https://prettier.io/docs/en/options.html On this page, I've noticed that the recommended way to apply settings is via the configuration file, which is documented here: https://prettier.io/docs/en/configuration.html在此页面上,我注意到应用设置的推荐方法是通过配置文件,记录在此处: https://prettier.io/docs/en/configuration.html

Upon reading the last link, I've just added ".prettierrc" file to the root of my project and added a single key so file looks as follow:阅读最后一个链接后,我刚刚将“.prettierrc”文件添加到项目的根目录并添加了一个键,因此文件如下所示:

{
  "printWidth": 120
}

After that, prettier works like a charm.在那之后,更漂亮的工作就像一个魅力。

PS Hate to keep my questions unanswered;) PS 讨厌让我的问题得不到回答;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM