Move all docs to website (#3139)
* Sync README -> docs/options.md * Sync README -> docs/*.md * Misc fixups * Remove markdown-toc * Remove insert-pragma from ToC * Never again! * Move all docs to ./docs * Remove yarn toc * Fix inter-doc links * Fix links in footer * Clean up README.md * Add basic description to README.md * Use flat badges * Move editor guides to website * Improve prettier-ignore docs * Fixup bad find/replace * Add JSON to README * Fix custom parser API link * Fixup GitHub centering, add downloads badge * Add 1.8 docs * docs(website): mention markdown on homepage (#1) * Add intro * Add watching-files.md * Fix markdown syntax highlighting * Switch back to .md links
This commit is contained in:
1 parent
8249b1c841
commit
71a5533c4e
40 files changed
+925
-1475
No files matched your search
@@ -0,0 +1,67 @@
|
||||
---
|
||||
id: precommit
|
||||
title: Pre-commit Hook
|
||||
---
|
||||
|
||||
You can use Prettier with a pre-commit tool. This can re-format your files that are marked as "staged" via `git add` before you commit.
|
||||
|
||||
## Option 1. [lint-staged](https://github.com/okonet/lint-staged)
|
||||
|
||||
Install it along with [husky](https://github.com/typicode/husky):
|
||||
|
||||
```bash
|
||||
yarn add lint-staged husky --dev
|
||||
```
|
||||
|
||||
and add this config to your `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"precommit": "lint-staged"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,json,css}": [
|
||||
"prettier --write",
|
||||
"git add"
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
There is a limitation where if you stage specific lines this approach will stage the whole file after regardless. See this [issue](https://github.com/okonet/lint-staged/issues/62) for more info.
|
||||
|
||||
See https://github.com/okonet/lint-staged#configuration for more details about how you can configure lint-staged.
|
||||
|
||||
|
||||
## Option 2. [pre-commit](https://github.com/pre-commit/pre-commit)
|
||||
|
||||
Copy the following config into your `.pre-commit-config.yaml` file:
|
||||
|
||||
```yaml
|
||||
|
||||
- repo: https://github.com/prettier/prettier
|
||||
sha: '' # Use the sha or tag you want to point at
|
||||
hooks:
|
||||
- id: prettier
|
||||
|
||||
```
|
||||
|
||||
Find more info from [here](http://pre-commit.com).
|
||||
|
||||
## Option 3. bash script
|
||||
|
||||
Alternately you can save this script as `.git/hooks/pre-commit` and give it execute permission:
|
||||
|
||||
```bash
|
||||
#!/bin/sh
|
||||
jsfiles=$(git diff --cached --name-only --diff-filter=ACM "*.js" "*.jsx" | tr '\n' ' ')
|
||||
[ -z "$jsfiles" ] && exit 0
|
||||
|
||||
# Prettify all staged .js files
|
||||
echo "$jsfiles" | xargs ./node_modules/.bin/prettier --write
|
||||
|
||||
# Add back the modified/prettified files to staging
|
||||
echo "$jsfiles" | xargs git add
|
||||
|
||||
exit 0
|
||||
```
|
||||
Reference in new issue
Block a user