首页 文章

Visual Studio Code Typescript避免在新行上使用参数

提问于
浏览
2

我正在开发一个关于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
 }

3 回答

  • 0

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

  • 0

    根据this

    editor.wordWrap:“off” - 行永远不会换行 . editor.wordWrap:“on” - 行将以视口宽度换行 . editor.wordWrap:“wordWrapColumn” - 行将换行于editor.wordWrapColumn的值 . editor.wordWrap:“bounded” - 行将以视口宽度的最小值和editor.wordWrapColumn的值进行换行 .

    你应该设置:

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

    对我来说 "prettier.printWidth": 180 并没有"prettier"在每个属性的开头都有"prettier"部分 .

    所以在 .prettierrc 我现在有 "printWidth": 180 修复了这个问题 .

相关问题