Goals
  1. Setup Prettier for different environments / IDEs

  2. Run Prettier via git hooks

Install Prettier

Install via npm

npm install --save-dev --save-exact prettier

Add empty configuration file

echo {}> .prettierrc.json

Create Prettier ignore file .prettierignore:

# Ignore artifacts:
build
coverage

Format all project files with Prettier:

npx prettier --write .

Git Hooks

Adding the following lines to the project’s package-json makes ESLint and Prettier run before each commit:

{
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "**/*": "prettier --write --ignore-unknown"
  }
}