如何在VSCode中正确使用全局Prettier配置?

huangapple go评论67阅读模式
英文:

How to propertly use global prettier config in vscode?

问题

我已在settings.json中全局配置了prettier设置。

"prettier.useTabs": false,
"prettier.trailingComma": "none",
"prettier.tabWidth": 4,
"prettier.bracketSpacing": true,
"prettier.singleQuote": true,
"prettier.withNodeModules": true,
"[javascript]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},

问题是,我克隆了一些开源存储库,其中包含一个.editorconfig文件,并且项目使用两个空格缩进。由于我配置了保存操作,所有代码都会使用prettier设置格式化,并忽略.editorconfig文件的设置。

最好的配置方式是什么,以便它使用项目配置而不是全局配置,是否使用全局prettier设置是一个好主意,还是应该始终考虑使用基于项目的.prettier文件?

英文:

I have globally configured prettier settings in settings.json

"prettier.useTabs": false,
"prettier.trailingComma": "none",
"prettier.tabWidth": 4,
"prettier.bracketSpacing": true,
"prettier.singleQuote": true,
"prettier.withNodeModules": true,
"[javascript]": {
    "editor.formatOnSave": true,
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},

The problem is I've cloned some opensource repository, that has .editorconfig file and project has two spaces, since i have configured onSave action all code is being formatted using prettier settings and ignores .editorconfig file settings.

What would be preferred way to configure it, so it use project configuration instead of global and is it even a good idea to use globall prettier settings or instead should i always consider to use project based .prettier file?

答案1

得分: 1

"prettier.useEditorConfig (默认值:true)":
在“受信任的项目”中默认情况下:
英文:

The default (in "trusted projects"):

"prettier.useEditorConfig": true

seems to work neat. It considers local .editorconfig overriding prettier (user) settings.

>prettier.useEditorConfig (default: true)
>
>Whether or not to take .editorconfig into account when parsing configuration.
>See the prettier.resolveConfig docs for details.
>
> Disabled on untrusted workspaces (always false)

Refs:

huangapple
  • 本文由 发表于 2023年5月7日 17:24:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76193073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定