在VS编码中编辑函数时,有没有办法在括号之前禁用空格?VS代码 - 函数括号之前的空格
可以说我有一个功能
function render() {
// some code here
}
当我开始编辑它,VS代码括号之前移除空间和转换此代码:
function render() {
// some code here
}
有没有一种方法来禁用此行为?
在VS编码中编辑函数时,有没有办法在括号之前禁用空格?VS代码 - 函数括号之前的空格
可以说我有一个功能
function render() {
// some code here
}
当我开始编辑它,VS代码括号之前移除空间和转换此代码:
function render() {
// some code here
}
有没有一种方法来禁用此行为?
我发现我有"editor.formatOnType": true
设置启用。这是编辑器在键入时自动格式化代码的原因。禁用它有助于解决问题。
我在VSCode团队。作为VSCode 1.8,这格式化选项,不支持开箱即用,但我们正在跟踪功能:https://github.com/Microsoft/vscode/issues/15386,https://github.com/Microsoft/TypeScript/issues/12234
作为一种变通方法,请尝试以下操作:
ext install eslint
"eslint.autoFixOnSave": true
到工作区或用户设置在项目的根目录,创建一个.eslintrc.json
有:
{
...
"rules": {
...
"space-before-function-paren": "error"
}
}
eslint扩展可以使用create .eslintrc.json
命令为您创建启动程序.eslintrc.json
。
这将自动格式化函数,以便在保存文件后有一个空格。
在我的情况,我想VS代码的正常缩进/格式化的行为,所以我禁用了eslint警告:
在.eslintrc。js文件我输入的规则里面:
'rules': {
....
//disable rule of space before function parentheses
"space-before-function-paren": 0
}
"javascript.format.insertSpaceBeforeFunctionParenthesis": true
function render() {
// some code here
}
"javascript.format.insertSpaceBeforeFunctionParenthesis": false
function render() {
// some code here
}
"editor.formatOnType": true
谢谢你告诉这个伟大的设置。这非常有用。直到VS Code的设置不违背这些Eslint规则。这不是解决我的问题的方法,编辑器在我编辑它们时仍会格式化我的函数,然后eslint突出显示错误,并且当我保存文件时,所有事情都恢复正常。这真的很烦人,很奇怪。 –
这应该是upvoted更多。自动格式化代码非常好,但自动“粘附”到eslint规范 – jschell12