Reputation: 3111
I've googled for a while and not found how to do this. I have eslint and prettier setup in my project.
// What I have:
if (a == b) doSomething();
// What I want from either eslint or prettier
if (a == b) {
doSomething();
}
Can any one show me how to get this done? Or show me their config that does this?
Upvotes: 24
Views: 8359
Reputation: 23291
To make this change programmatically and comprehensively throughout your code base, assuming your package.json
looks something like this
{
...
"scripts": {
...
"format": "prettier --write .",
"lint": "eslint .",
}
}
do this:
.eslintrc.js
just like the accepted answer suggests{
"rules": {
"curly": "error",
}
}
npm run lint -- --fix
npm run format
Upvotes: 1
Reputation: 3189
tl;dr : create a .eslintrc.json for your project and a rule for curly.
{
"rules": {
"curly": "error",
}
}
Prettier only prints code. It does not transform it. This is to limit the scope of Prettier. Let's focus on the printing and do it really well!
Here are a few examples of things that are out of scope for Prettier:
so to get what you want, you should use eslint. eslint has a --fix
option and a rule for all
, which would provide exactly what you want.
Hope this helps.
Upvotes: 18