简体   繁体   English

vscode 中 Prettier 配置的问题

[英]Problems with Prettier config in vscode

I have a standard Angular app and am trying to disable trailing commas in Prettier .我有一个标准的 Angular 应用程序,并试图在Prettier 中禁用尾随逗号。 So I go into vscode settings (both user and workspace) and set trailing commas to none:所以我进入 vscode 设置(用户和工作区)并将尾随逗号设置为无:

在此处输入图片说明

I also have an .editorconfig file and tslint.json files.我还有一个.editorconfig文件和tslint.json文件。 The tslint.json file has trailing commas set to false. tslint.json文件的尾随逗号设置为 false。 Lastly, I am using the Prettier Formatter for VSCode extension.最后,我将 Prettier Formatter 用于 VSCode 扩展。 Anyway, the trailing commas still appear unless I put this in package.json:无论如何,除非我把它放在 package.json 中,否则尾随逗号仍然会出现:

"prettier": {
    "bracketSpacing": true,
    "singleQuote": true,
    "trailingComma": "none"
 }

How come if my preferences are set in VSCode settings that I then have to add this snippet of redundant code in the package.json file?如果我的首选项是在 VSCode 设置中设置的,那么我必须在package.json文件中添加这段冗余代码怎么办?

Thanks for any helpful tips.感谢您提供任何有用的提示。

Maybe you have to set "trailing-comma": true in tslint.json .也许您必须在tslint.json 中设置"trailing-comma": true Anyway good practice is to install https://github.com/prettier/tslint-config-prettier so you don't get conflicts.无论如何,好的做法是安装https://github.com/prettier/tslint-config-prettier以免发生冲突。

Is your default formatter set to prettier?您的默认格式化程序是否设置为更漂亮? Or the default Typescript and Javascript language features?还是默认的Typescript and Javascript language features?

You can check this by opening a typescript file and pressing ctrl + shift + p (for windows)您可以通过打开打字稿文件并按ctrl + shift + p (对于 Windows)来检查这一点

and looking for format document with and looking which is the default.并查找format document with并查找默认设置。

删除 tslint 配置中的“尾随逗号”。

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

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