From 324fc866184f7008b6a8ed372efbe69ac0aa598e Mon Sep 17 00:00:00 2001 From: Lucas Azzola Date: Sat, 8 Jul 2017 17:45:52 +1000 Subject: [PATCH] Sync usage.md from main README --- docs/en/usage.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/en/usage.md b/docs/en/usage.md index f5f6e4a1..7e421f56 100644 --- a/docs/en/usage.md +++ b/docs/en/usage.md @@ -132,16 +132,14 @@ See https://github.com/okonet/lint-staged#configuration for more details about h #### Option 2. [pre-commit](https://github.com/pre-commit/pre-commit) -Copy the following config in your pre-commit config yaml file: +Copy the following config into your `.pre-commit-config.yaml` file: ```yaml - - repo: https://github.com/awebdeveloper/pre-commit-prettier + - repo: https://github.com/prettier/prettier sha: '' # Use the sha or tag you want to point at hooks: - id: prettier - additional_dependencies: ['prettier@1.4.2'] - ``` Find more info from [here](https://github.com/awebdeveloper/pre-commit-prettier). @@ -151,18 +149,17 @@ Find more info from [here](https://github.com/awebdeveloper/pre-commit-prettier) Alternately you can save this script as `.git/hooks/pre-commit` and give it execute permission: ```bash -!/bin/sh +#!/bin/sh jsfiles=$(git diff --cached --name-only --diff-filter=ACM | grep '\.jsx\?$' | tr '\n' ' ') [ -z "$jsfiles" ] && exit 0 -diffs=$(node_modules/.bin/prettier -l $jsfiles) -[ -z "$diffs" ] && exit 0 +# Prettify all staged .js files +echo "jsfiles" | xargs ./node_modules/.bin/prettier --write -echo "here" -echo >&2 "Javascript files must be formatted with Prettier. Please run:" -echo >&2 "node_modules/.bin/prettier --write "$diffs"" +# Add back the modified/prettified files to staging +echo "jsfiles" | xargs git add -exit 1 +exit 0 ``` ## API