From 291871df530e43fdbba4f2e93deb99509da7f09d Mon Sep 17 00:00:00 2001 From: Andrey Okonetchnikov Date: Thu, 16 Feb 2017 02:52:03 +0100 Subject: [PATCH] =?UTF-8?q?docs:=20Add=20pre-commit=20hook=20with=20?= =?UTF-8?q?=F0=9F=9A=AB=F0=9F=92=A9=20lint-staged=20section=20to=20the=20R?= =?UTF-8?q?EADME=20(#714)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2610fc41..c4ab3082 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