简体   繁体   English

更漂亮的格式代码由我编写,而不是整个团队

[英]Prettier format code write by me, not the whole team

I am a programmer, and I started using prettier, I want prettier to format the code write only by me, for example if I open a JavaScript file pushed on Git by other members of the team, I dont want that code to be formated.我是一名程序员,我开始使用 prettier,我希望 prettier 格式化只有我写的代码,例如,如果我打开一个 JavaScript 文件,由团队的其他成员推送到 Git,我不希望该代码被格式化。 Is there any posibility?有没有可能?

Searched on the web but nothing found在 web 上搜索,但没有找到

Setting: Format On Save Mode设置:格式化保存模式

Visual Studio Code has a setting "Format On Save Mode", which you can set to "modifications", which will only format the changes you made. Visual Studio Code 有一个设置“Format On Save Mode”,您可以将其设置为“modifications”,它只会格式化您所做的更改。
You might need some experimentation with this feature but it promises exactly what you are asking.您可能需要对此功能进行一些试验,但它完全可以满足您的要求。

  1. File -> Preferences -> Settings文件 -> 首选项 -> 设置
  2. Search for format搜索格式
  3. Find Editor: Format On Save Mode查找编辑器:格式保存模式
  4. Change value to modifications更改修改
  5. Evaluate the other auto-formatting options if they make sense to deactivate评估其他自动格式化选项(如果停用有意义)

See screenshot below:请参见下面的屏幕截图:
在此处输入图像描述

There is no option for that, but you can ignore the code you don't want to format with specific comments.没有选项,但您可以忽略不想用特定注释格式化的代码。

eg to ignore js code you need to type // prettier-ignore例如,要忽略 js 代码,您需要键入 // prettier-ignore

// prettier-ignore
matrix(
  1, 0, 0,
  0, 1, 0,
  0, 0, 1
)

You can check their documentation to learn more: https://prettier.io/docs/en/ignore.html您可以查看他们的文档以了解更多信息: https://prettier.io/docs/en/ignore.html

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

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