我想在Visual Studio Code中保存文件时使用内置格式化程序自动格式化TypeScript代码。
我知道以下选项,但它们都不够好:
Shift + Alt + F
"editor.formatOnType": true
按Enter键时会格式化该行。不幸的是,当您鼠标单击另一条线或按向上/向下箭头时,它会使其保持未格式化。"beautify.onSave": true
它不适用于TypeScript{
"editor.formatOnSave": true
}
如果您想使用Javascript源自动格式保存,请将此一个添加到Users Setting
(按Cmd或Ctrl,):
"[javascript]": { "editor.formatOnSave": true }
对于MAC用户,将此行添加到默认设置中
文件路径为:/ Users / USER_NAME / Library / Application Support / Code / User / settings.json
“tslint.autoFixOnSave”:是的
该文件的样本将是:
{
"window.zoomLevel": 0,
"workbench.iconTheme": "vscode-icons",
"typescript.check.tscVersion": false,
"vsicons.projectDetection.disableDetect": true,
"typescript.updateImportsOnFileMove.enabled": "always",
"eslint.autoFixOnSave": true,
"tslint.autoFixOnSave": true
}