UNPKG

5.01 kBMarkdownView Raw
1# `pretty-quick`
2
3[![GitHub Actions](https://github.com/prettier/pretty-quick/workflows/CI/badge.svg)](https://github.com/prettier/pretty-quick/actions/workflows/ci.yml)
4[![Codecov](https://img.shields.io/codecov/c/github/prettier/pretty-quick.svg)](https://codecov.io/gh/prettier/pretty-quick)
5[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fun-ts%2Flib-boilerplate%2Fmain%2Fpackage.json)](https://github.com/plantain-00/type-coverage)
6[![npm](https://img.shields.io/npm/v/pretty-quick.svg)](https://www.npmjs.com/package/pretty-quick)
7[![GitHub Release](https://img.shields.io/github/release/prettier/pretty-quick)](https://github.com/prettier/pretty-quick/releases)
8
9[![Conventional Commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
10[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com)
11[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
12[![Code Style: Prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
13[![changesets](https://img.shields.io/badge/maintained%20with-changesets-176de3.svg)](https://github.com/changesets/changesets)
14
15> Get Pretty Quick
16
17Runs [Prettier](https://prettier.io) on your changed files.
18
19![demo](./img/demo.gif)
20
21Supported source control managers:
22
23- Git
24- Mercurial
25
26## Install
27
28```sh
29# npm
30npm install -D prettier pretty-quick
31```
32
33```sh
34# yarn
35yarn add -D prettier pretty-quick
36```
37
38## Usage
39
40```sh
41# npx
42npx pretty-quick
43
44# yarn
45yarn pretty-quick
46```
47
48## Pre-Commit Hook
49
50You can run `pretty-quick` as a `pre-commit` hook using [`simple-git-hooks`](https://github.com/toplenboren/simple-git-hooks).
51
52```sh
53# npm
54npm install -D simple-git-hooks
55
56# yarn
57yarn add -D simple-git-hooks
58```
59
60In `package.json`, add:
61
62```json
63"simple-git-hooks": {
64 "pre-commit": "pretty-quick --staged"
65}
66```
67
68## CLI Flags
69
70### `--staged` (only git)
71
72Pre-commit mode. Under this flag only staged files will be formatted, and they will be re-staged after formatting.
73
74Partially 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.
75
76### `--no-restage` (only git)
77
78Use with the `--staged` flag to skip re-staging files after formatting.
79
80### `--branch`
81
82When not in `staged` pre-commit mode, use this flag to compare changes with the specified branch. Defaults to `master` (git) / `default` (hg) branch.
83
84### `--pattern`
85
86Filters the files for the given [minimatch](https://github.com/isaacs/minimatch) pattern.
87For example `pretty-quick --pattern "**/*.*(js|jsx)"` or `pretty-quick --pattern "**/*.js" --pattern "**/*.jsx"`
88
89### `--verbose`
90
91Outputs the name of each file right before it is processed. This can be useful if Prettier throws an error and you can't identify which file is causing the problem.
92
93### `--bail`
94
95Prevent `git commit` if any files are fixed.
96
97### `--check`
98
99Check that files are correctly formatted, but don't format them. This is useful on CI to verify that all changed files in the current branch were correctly formatted.
100
101### `--no-resolve-config`
102
103Do not resolve prettier config when determining which files to format, just use standard set of supported file types & extensions prettier supports. This may be useful if you do not need any customization and see performance issues.
104
105By default, pretty-quick will check your prettier configuration file for any overrides you define to support formatting of additional file extensions.
106
107Example `.prettierrc` file to support formatting files with `.cmp` or `.page` extensions as html.
108
109```json
110{
111 "printWidth": 120,
112 "bracketSpacing": false,
113 "overrides": [
114 {
115 "files": "*.{cmp,page}",
116 "options": { "parser": "html" }
117 }
118 ]
119}
120```
121
122<!-- Undocumented = Unsupported :D
123
124### `--config`
125
126Path to a `.prettierrc` file.
127
128### `--since`
129
130A SCM revision such as a git commit hash or ref.
131
132For example `pretty-quick --since HEAD` will format only staged files.
133
134-->
135
136### `--ignore-path`
137
138Check an alternative file for ignoring files with the same format as [`.prettierignore`](https://prettier.io/docs/en/ignore#ignoring-files).
139For example `pretty-quick --ignore-path .gitignore`
140
141## Configuration and Ignore Files
142
143`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 if you don't use `--ignore-path` . Configuration files will be found by searching up the file system. `.prettierignore` files are only found from the repository root and the working directory that the command was executed from.