Reputation: 6675
In VSCode, each time I save a JS file, Prettier removes the space between the function keyword and its parenthesis.
It changes this:
function (parameter)
To this:
function(parameter)
But I want to keep the space.
Some people are suggesting adding this rule to VSCode setting:
"prettier.spaceBeforeFunctionParen": true
But apparently this rule doesn't exist any more.
How can I force a space between function and parenthesis in Prettier?
Upvotes: 14
Views: 29629
Reputation: 4414
Interestingly, I get the opposite behavior.
I have VSCode set up to use my .prettierrc
config file. But when I set VSCode to "Format on Save", a space gets added before my function parens, even when I have this set to false in .prettierrc: “spaceBeforeFunctionParen": false
.
This function signature:
const myFunction = function(datevalue) {
... always changes to:
const myFunction = function (datevalue) {
I can't find a way to avoid this with prettier. So, in part because the extraneous space looks peculiar to me, I now pretty much always just use arrow functions instead:
const myFunction = (datevalue) => {
Upvotes: 5
Reputation: 87
To solve that issue you had to set the config on your settings.js:
{
"editor.formatOnSave": false,
"editor.formatOnType": false
}
or go to the vscode settings "File => Preferences => settings" search for onSave and unchecked the "Format On Save" check box.
Upvotes: -2
Reputation: 340
in setting.json add
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
after, when you save your work, eslint fix your error like space before function parenthese.
Upvotes: 11