Search code examples
javascriptvisual-studio-codejs-beautify

No space before opening parenthesis on auto format in VS Code


If I press Shift + Alt + F to let VS Code format my JS source code it converts

for(var key in indexObj)

to

for (var key in indexObj)

How can I prevent VS Code to do that?


Solution

    • Install the beautify plugin for VSCode
    • Create a .jsbeautifyrc file. Take this one as an example
    • Set its space_before_conditional value to false
    • Place the file in your home directory to use it globally or place it in the same folder as the .js are located which you want to format
    • Press Shift+Alt+F to get your code formatted