1 | # `pretty-quick`
|
2 |
|
3 | [![Travis](https://img.shields.io/travis/azz/pretty-quick.svg?style=flat-square)](https://travis-ci.org/azz/pretty-quick)
|
4 | [![Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
|
5 | [![npm](https://img.shields.io/npm/v/pretty-quick.svg?style=flat-square)](https://npmjs.org/pretty-quick)
|
6 | [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg?style=flat-square)](https://github.com/semantic-release/semantic-release)
|
7 | [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE)
|
8 |
|
9 | > Get Pretty Quick
|
10 |
|
11 | Runs [Prettier](https://prettier.io) on your changed files.
|
12 |
|
13 | ![demo](./img/demo.gif)
|
14 |
|
15 | Supported source control managers:
|
16 |
|
17 | * Git
|
18 | * Mercurial
|
19 |
|
20 | ## Install
|
21 |
|
22 | With `yarn`:
|
23 |
|
24 | ```shellsession
|
25 | yarn add --dev prettier pretty-quick
|
26 | ```
|
27 |
|
28 | With `npm`:
|
29 |
|
30 | ```shellsession
|
31 | npm install --save-dev prettier pretty-quick
|
32 | ```
|
33 |
|
34 | ## Usage
|
35 |
|
36 | With `yarn`:
|
37 |
|
38 | ```shellsession
|
39 | yarn pretty-quick
|
40 | ```
|
41 |
|
42 | With [`npx`](https://npm.im/npx): (No install required)
|
43 |
|
44 | ```shellsession
|
45 | npx pretty-quick
|
46 | ```
|
47 |
|
48 | With `npm`:
|
49 |
|
50 | 1. Add `"pretty-quick": "pretty-quick"` to the scripts section of `package.json`.
|
51 | 2. `npm run pretty-quick`
|
52 |
|
53 | ## Pre-Commit Hook
|
54 |
|
55 | You can run `pretty-quick` as a pre-commit hook using [`husky`](https://github.com/typicode/husky).
|
56 |
|
57 | > For Mercurial have a look at [`husky-hg`](https://github.com/TobiasTimm/husky-hg)
|
58 |
|
59 | ```shellstream
|
60 | yarn add --dev husky
|
61 | ```
|
62 |
|
63 | In `package.json`'s `"scripts"` section, add:
|
64 |
|
65 | ```
|
66 | "precommit": "pretty-quick --staged"
|
67 | ```
|
68 |
|
69 | ![demo](./img/precommit.gif)
|
70 |
|
71 | ## CLI Flags
|
72 |
|
73 | ### `--staged` (only git)
|
74 |
|
75 | Pre-commit mode. Under this flag only staged files will be formatted, and they will be re-staged after formatting.
|
76 |
|
77 | Partially staged files will not be re-staged after formatting and pretty-quick will exit with a non-zero exit code. The intent is to abort the git commit and allow the user to amend their selective staging to include formatting fixes.
|
78 |
|
79 | ### `--branch`
|
80 |
|
81 | When not in `staged` pre-commit mode, use this flag to compare changes with the specified branch. Defaults to `master` (git) / `default` (hg) branch.
|
82 |
|
83 |
|
84 |
|
85 | ### `--config`
|
86 |
|
87 | Path to a `.prettierrc` file.
|
88 |
|
89 | ### `--since`
|
90 |
|
91 | A SCM revision such as a git commit hash or ref.
|
92 |
|
93 | For example `pretty-quick --since HEAD` will format only staged files.
|
94 |
|
95 | -->
|
96 |
|
97 | ## Configuration and Ignore Files
|
98 |
|
99 | `pretty-quick` will respect your [`.prettierrc`](https://prettier.io/docs/en/configuration), [`.prettierignore`](https://prettier.io/docs/en/ignore#ignoring-files), and [`.editorconfig`](http://editorconfig.org/) files, so there's no additional setup required. Configuration files will be found by searching up the file system. `.prettierignore` files are only found from the working directory that the command was executed from.
|