Search code examples
javascriptprettier

vscode prettier plugin lack of spaces breaks linter rule


On a node project my prettier plugin acts different than on projects created with create-react-app.

When I write code like:

var test = { a: 1
};

and save the file in a react app it pretties to:

var test = { a: 1 };

In the node project it pretties to:

 var test = {a: 1};

This will have the linter complain A space is required before '}'.

I can't figure out why prettier would behave differently for an app created with create-react app. The have the same vscode settings and the same prettier.yml.

I am using Prettier code formatter

This spaces problem prevents me from making pull requests because the code will fail the linter.

I guess I can create a bash script that auto fixes linting errors but was wondering why I would have to do this in the first place since the React apps don't have this problem.


Solution

  • Not much can be said without seeing config files and Prettier setup. Spacing before and after { and } is configured by bracketSpacing: true option in prettier config. You should check if it is specified in the config file: if not, theoretically, it can be pulled from elsewhere in your Node project.