Yan*_*ich 30 visual-studio-code
有没有办法在VS代码中编辑函数时禁用删除括号前的空格?
让我们说我有一个功能
function render () {
// some code here
}
Run Code Online (Sandbox Code Playgroud)
当我开始编辑它时,VS Code删除括号前的空格并将此代码转换为:
function render() {
// some code here
}
Run Code Online (Sandbox Code Playgroud)
有没有办法禁用这种行为?
Ale*_*gle 33
"javascript.format.insertSpaceBeforeFunctionParenthesis": true
function render () {
// some code here
}Run Code Online (Sandbox Code Playgroud)
"javascript.format.insertSpaceBeforeFunctionParenthesis": false
function render() {
// some code here
}Run Code Online (Sandbox Code Playgroud)
"editor.formatOnType": true小智 26
我对匿名函数有相反的问题.我们使用更漂亮的扩展.自动更正在括号前插入空格.然后更漂亮的抱怨它.
var anonfunc = function() {
// Expected syntax.
}
var autocorrected = function () {
// Auto-correct inserts a space
}
Run Code Online (Sandbox Code Playgroud)
有类似的代码选项,它解决了我的问题:
"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false
Run Code Online (Sandbox Code Playgroud)
默认情况下是true.花了我一些时间,直到我累了纠正自动纠正.
我在 VSCode 在构造函数和 ESLint 抱怨之后删除空格时遇到了类似的问题,因为没有空格。
constructor JavaScript › Format: Insert Space After Constructor就我而言,我想要 VS Code 的正常缩进/格式化行为,因此我禁用了 eslint 警告:
在 .eslintrc.js 文件中,我在规则中输入:
'rules': {
....
//disable rule of space before function parentheses
"space-before-function-paren": 0
}
Run Code Online (Sandbox Code Playgroud)
我在VSCode团队中。从VSCode 1.8开始,不支持立即使用此格式设置选项,但是我们正在跟踪该功能:https : //github.com/Microsoft/vscode/issues/15386,https : //github.com/Microsoft/TypeScript /问题/ 12234
作为一种解决方法,请尝试以下操作:
ext install eslint"eslint.autoFixOnSave": true到您的工作区或用户设置在项目的根目录中,创建一个.eslintrc.json带有:
{
...
"rules": {
...
"space-before-function-paren": "error"
}
}
Run Code Online (Sandbox Code Playgroud)
eslint扩展可以.eslintrc.json使用create .eslintrc.json命令为您创建启动器。
保存文件时,这将自动格式化函数以在其后留一个空格。
| 归档时间: |
|
| 查看次数: |
21902 次 |
| 最近记录: |