admin管理员组

文章数量:1252850

I'm using shift + alt + f for sorting my code in vscode but why I'm Getting This Error:?

Error:

[eslint] There should be no space after '{' (babel/object-curly-spacing)

Code:

 User.findOne({ _id: temp }, (obj) => {

After removing space before _id and after temp, I haven't any error But How Should I Fix in vscode for auto arrange?

I'm using shift + alt + f for sorting my code in vscode but why I'm Getting This Error:?

Error:

[eslint] There should be no space after '{' (babel/object-curly-spacing)

Code:

 User.findOne({ _id: temp }, (obj) => {

After removing space before _id and after temp, I haven't any error But How Should I Fix in vscode for auto arrange?

Share Improve this question asked Jan 20, 2018 at 0:44 Saeed HeidarizareiSaeed Heidarizarei 8,91622 gold badges66 silver badges111 bronze badges 5
  • So did you configure VSCode to use eslint for formatting? – epascarello Commented Jan 20, 2018 at 0:50
  • I just instaled eslint and added editor.tabSize": 2, and editor.detectIndentation": false – Saeed Heidarizarei Commented Jan 20, 2018 at 0:52
  • 1 You've told VS to use eslint to check your coding style, so it warns about style problems like this. – Barmar Commented Jan 20, 2018 at 1:12
  • I want to use alt shift f with no problem, how to say vscode remove that space? , if that space is a problem, why vscode added that extra space? – Saeed Heidarizarei Commented Jan 20, 2018 at 1:30
  • Find the place where you can configure eslint options, and turn off babel/object-curly-spacing checks. – Barmar Commented Jan 20, 2018 at 2:07
Add a comment  | 

4 Answers 4

Reset to default 10

In your VS Code settings, change javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces to false so it won't add those spaces before and after braces.

See here for more options related to formatting of Javascript code in VS.

as described in the official site eslint.org just added the blow line in .eslint.trc file

"object-curly-spacing": [2, "always"]

in eslint just add

rules:{
 "arraysInObjects": false,
}

or run

npm run lint -- --fix

To prevent vscode from addin spaces when formatting your code.

Open settings.json and add the following lines

"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,

This make the fix on both javascript and typescript formatters

本文标签: javascriptThere should be no space after 3939 (babelobjectcurlyspacing)Stack Overflow