Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code - space before function parentheses

Is there a way to disable removing space before parentheses when editing a function in VS Code?

Lets say I have a function

function render () {     // some code here } 

When I start editing it, VS Code removes the space before parentheses and transforms this code to:

function render() {     // some code here } 

Is there a way to disable this behavior?

like image 337
Yan Takushevich Avatar asked Dec 14 '16 19:12

Yan Takushevich


People also ask

How do you add space between words in VSCode?

In VS Code, press Ctrl+P and execute ext install insert-spaces .

How do you rearrange VS code?

On Windows Shift + Alt + F. On Mac Shift + Option + F. On Linux Ctrl + Shift + I.


Video Answer


2 Answers

  1. In VS Code open File -> Preferences -> Settings
  2. Add to your JSON config:

"javascript.format.insertSpaceBeforeFunctionParenthesis": true

function render () {      // some code here  }

"javascript.format.insertSpaceBeforeFunctionParenthesis": false

function render() {      // some code here  }
  1. Now you can continue using your auto format option "editor.formatOnType": true
like image 69
Alex Eagle Avatar answered Sep 19 '22 21:09

Alex Eagle


I had opposite problem with anonymous functions. We use prettier extension. Auto-correct inserts a space before parenthesis. And then prettier complains about it.

var anonfunc = function() {     // Expected syntax.  }  var autocorrected = function () {     // Auto-correct inserts a space } 

There is similar code option, which solves my problem:

"javascript.format.insertSpaceAfterFunctionKeywordForAnonymousFunctions": false 

By default it is true. Took me some time, until I was tired correcting auto-correct.

like image 23
Zmogas Avatar answered Sep 17 '22 21:09

Zmogas