April 5, 2020
Use prettier to focus on the code and not on the formatting.
Prettier is a great tool for automatically formatting your code in a consistent way across your codebases, regardless of individual contributor preferences.
Prettier can take something like:
function HelloWorld({greeting = "hello", greeted = 'World'}) {
if(!greeting){return null};
return greeting+" "+greeted;
}
and format it beautifully like
function HelloWorld({ greeting = "hello", greeted = "World" }) {
  if (!greeting) {
    return null;
  }
  return greeting + " " + greeted;
}
Add prettier to your project
npm install prettier --save-dev --save-exact
Run against all your files
npx prettier --write src/**/*
Run prettier automatically when committing files
npm install --save-dev pretty-quick husky
Then add this config to package.json:
{
  "husky": {
    "hooks": {
      "pre-commit": "pretty-quick --staged"
    }
  }
}
Further reading...