【问题标题】:Visual Studio Code Typescript avoid parameters on new lineVisual Studio Code Typescript 避免新行参数
【发布时间】:2018-04-06 22:31:50
【问题描述】:

我正在开发一个关于 Visual Studio Code 的 Angular 项目,但我在 Typescript 文件中遇到了一个烦人的格式文档设置,它会将参数换成新行:

格式化前(alt+shift+f):

this.opportunityId = this.route.snapshot.paramMap.get('opportunityid');
this.opportunityTermVendorId = this.route.snapshot.paramMap.get('vendorid');
this.opportunityTermVendorAssetId = this.route.snapshot.paramMap.get('assetid');
this.opportunityTermCollateralId = this.route.snapshot.paramMap.get('collateralid');

格式化后(alt+shift+f):

this.opportunityId = this.route.snapshot.paramMap.get('opportunityid');
this.opportunityTermVendorId = this.route.snapshot.paramMap.get('vendorid');
this.opportunityTermVendorAssetId = this.route.snapshot.paramMap.get(
  'assetid'
);
this.opportunityTermCollateralId = this.route.snapshot.paramMap.get(
  'collateralid'
);

我关闭了自动换行,但我仍然尝试将其设置为更大的自动换行列值。查看我当前的设置覆盖

{
   "git.confirmSync": false,
   "terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
   "workbench.iconTheme": "material-icon-theme",
   "editor.formatOnSave": true,
   "prettier.singleQuote": true,
   "editor.wordWrapColumn": 180
 }

【问题讨论】:

    标签: angular typescript visual-studio-code


    【解决方案1】:

    对我来说"prettier.printWidth": 180 不起作用,但事实证明,最新版本的 prettier 在每个属性的开头都没有“prettier”部分。

    所以在.prettierrc 我现在有"printWidth": 180 解决了这个问题。

    【讨论】:

      【解决方案2】:

      根据this

      editor.wordWrap: "off" - 行永远不会换行。
      editor.wordWrap: "on" - 行将在视口宽度处换行。
      editor.wordWrap: "wordWrapColumn" - 行将在 editor.wordWrapColumn 的值处换行。 editor.wordWrap: "bounded" - 行将在视口宽度的最小值和 editor.wordWrapColumn 的值处换行。

      你应该设置:

      "editor.wordWrap": "bounded",
      "editor.wordWrapColumn": 180
      

      【讨论】:

      • 您好,感谢您的帮助,在搞砸了一点之后,我发现“Angular Essentials”附带的名为“Prettier”的扩展导致了这个问题。我只需要添加“prettier.printWidth”:160
      • 当前版本不适合我。默认情况下,它设置为关闭 - 我仍然看到相同的行为。即使在我使用您提供的设置覆盖了 dafult 行为之后 - 格式化后我仍然会看到同样奇怪的新行。如果您有更新信息 - 请查看stackoverflow.com/questions/47209641/…
      【解决方案3】:

      我发现“Angular Essentials”附带的名为“Prettier”的扩展导致了这个问题。我只需要在设置中添加 "prettier.printWidth": 160。

      【讨论】:

      • 我也得到了同样的结果。但是,将 "prettier.printWidth": 160 置于设置中不会影响行为。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 1970-01-01
      • 2023-01-17
      相关资源
      最近更新 更多