UNPKG

2.88 kBMarkdownView Raw
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
11Runs [Prettier](https://prettier.io) on your changed files.
12
13![demo](./img/demo.gif)
14
15Supported source control managers:
16
17* Git
18* Mercurial
19
20## Install
21
22With `yarn`:
23
24```shellsession
25yarn add --dev prettier pretty-quick
26```
27
28With `npm`:
29
30```shellsession
31npm install --save-dev prettier pretty-quick
32```
33
34## Usage
35
36With `yarn`:
37
38```shellsession
39yarn pretty-quick
40```
41
42With [`npx`](https://npm.im/npx): (No install required)
43
44```shellsession
45npx pretty-quick
46```
47
48With `npm`:
49
501. Add `"pretty-quick": "pretty-quick"` to the scripts section of `package.json`.
512. `npm run pretty-quick`
52
53## Pre-Commit Hook
54
55You 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
60yarn add --dev husky
61```
62
63In `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
75Pre-commit mode. Under this flag only staged files will be formatted, and they will be re-staged after formatting.
76
77Partially 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
81When 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<!-- Undocumented = Unsupported :D
84
85### `--config`
86
87Path to a `.prettierrc` file.
88
89### `--since`
90
91A SCM revision such as a git commit hash or ref.
92
93For 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.