如何停止VS。代码会破坏我的代码格式吗?

时间:2019-08-20 07:04:24

标签: visual-studio-code vscode-settings code-formatting

是否有某种方式可以编写/下载VS规则。代码应该格式化代码吗?

示例:

我有以下格式精美的(JavaScript)代码:

var boundingBox        = Object.create(null);
    boundingBox.top    = 0;
    boundingBox.left   = 0;
    boundingBox.right  = window.innerWidth;
    boundingBox.bottom = window.innerHeight;

但是在我这样做之后:Right-click --> Format Document

它将其破坏为(相对)丑陋且“不可读”的混乱:

var boundingBox = Object.create(null);
boundingBox.top = 0;
boundingBox.left = 0;
boundingBox.right = window.innerWidth;
boundingBox.bottom = window.innerHeight;

是否有一些plugin / .edditorconfig规则/设置/我可以告诉VS的其他方法。代码应该如何格式化代码? (或至少不破坏现有格式?)

1 个答案:

答案 0 :(得分:1)

我认为您想要的是此扩展名: https://marketplace.visualstudio.com/items?itemName=wwm.better-align

它允许您按冒号(:),赋值(=+=-=*=,/=)和箭头( =>

但是,我个人认为适应其他代码格式样式可能是值得的。根据我的经验,按特定字符对齐代码不是常见的做法。