diff --git a/README.md b/README.md index 2610fc416..c4ab30824 100644 --- a/README.md +++ b/README.md @@ -124,6 +124,34 @@ prettier --write 'src/**/*.js' 'bin/*.js' In the future we will have better support for formatting whole projects. +#### Pre-commit hook for changed files + +[🚫💩 lint-staged](https://github.com/okonet/lint-staged) can re-format your files that are marked as "staged" via `git add` before you commit. + +Install it along with [pre-commit](https://github.com/observing/pre-commit) (or [husky](https://github.com/typicode/husky)): + +```bash +npm install --save-dev lint-staged pre-commit +``` + +and add this config to your `package.json`: + +```json +{ + "scripts": { + "lint:staged": "lint-staged" + }, + "lint-staged": { + "*.js": [ + "prettier --write", + "git add" + ] + }, + "pre-commit": "lint:staged" +} +``` + + ### API The API is a single function exported as `format`. The options @@ -206,7 +234,7 @@ Install the [JavaScript Prettier extension](https://github.com/madskristensen/Ja ### Sublime Text -Sublime Text support is available through Package Control and +Sublime Text support is available through Package Control and the [JsPrettier](https://packagecontrol.io/packages/JsPrettier) plug-in. ### JetBrains