How to Configure Prettier/ESLint to Keep Space Between Function Name and Parentheses? VS Code

222 Views Asked by At

I'm using Visual Studio Code for a JavaScript project and facing a formatting challenge with Prettier, which I'm using in conjunction with ESLint. My preference is to maintain a space between the function name and the opening parenthesis. However, after formatting with Prettier, this space is being removed.

Desired Formatting:

function name (args) {
  // function body
}

Current Formatting by Prettier:

function name(args) {
  // function body
}

So far, I have tried adding "javascript.format.insertSpaceBeforeFunctionParenthesis": true to my settings.json file in VS Code, but this hasn't resolved the issue. I am looking for a way to configure either Prettier, ESLint, or VS Code to achieve this specific formatting style.

Is there a configuration option in Prettier, ESLint, or a VS Code setting that can enforce this space? Any guidance on adjusting settings or rules to preserve this space consistently across my codebase would be greatly appreciated.

1

There are 1 best solutions below

1
mimikyu On

Searching around I found this: https://itecnote.com/tecnote/prettier-add-space-between-function-and-parenthesis/, might be of help?

Just mirroring here in case the link goes down, the suggested solution is to add:

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
}

to settings.json.