1 | # prettier-eslint-cli
|
2 |
|
3 | CLI for [`prettier-eslint`][prettier-eslint]
|
4 |
|
5 | [![Build Status][build-badge]][build]
|
6 | [![Code Coverage][coverage-badge]][coverage]
|
7 | [![version][version-badge]][package]
|
8 | [![downloads][downloads-badge]][npm-stat]
|
9 | [![MIT License][license-badge]][LICENSE]
|
10 |
|
11 | [![All Contributors](https://img.shields.io/badge/all_contributors-19-orange.svg?style=flat-square)](#contributors)
|
12 | [![PRs Welcome][prs-badge]][prs]
|
13 | [![Donate][donate-badge]][donate]
|
14 | [![Code of Conduct][coc-badge]][coc]
|
15 | [![Roadmap][roadmap-badge]][roadmap]
|
16 | [![Examples][examples-badge]][examples]
|
17 |
|
18 | [![Watch on GitHub][github-watch-badge]][github-watch]
|
19 | [![Star on GitHub][github-star-badge]][github-star]
|
20 | [![Tweet][twitter-badge]][twitter]
|
21 |
|
22 | ## The problem
|
23 |
|
24 | You have a bunch of files that you want to format using [`prettier-eslint`][prettier-eslint].
|
25 | But `prettier-eslint` can only operate on strings.
|
26 |
|
27 | ## This solution
|
28 |
|
29 | This is a [CLI](https://en.wikipedia.org/wiki/Command-line_interface) that allows you to use
|
30 | `prettier-eslint` on one or multiple files. `prettier-eslint-cli` forwards on the `filePath`
|
31 | and other relevant options to `prettier-eslint` which identifies the applicable `ESLint`
|
32 | config for each file and uses that to determine the options for `prettier` and `eslint --fix`.
|
33 |
|
34 | ## Installation
|
35 |
|
36 | This module is distributed via [npm][npm] which is bundled with [node][node] and should
|
37 | be installed (with [`yarn`][yarn]) as one of your project's `devDependencies`:
|
38 |
|
39 | ```
|
40 | yarn add --dev prettier-eslint-cli
|
41 | ```
|
42 |
|
43 | > If you're still using the [`npm`][npm] client: `npm install --save-dev prettier-eslint-cli`
|
44 |
|
45 | ## Usage
|
46 |
|
47 | Typically you'll use this in your [npm scripts][npm scripts] (or [package scripts][package scripts]):
|
48 |
|
49 | ```json
|
50 | {
|
51 | "scripts": {
|
52 | "format": "prettier-eslint \"src/**/*.js\""
|
53 | }
|
54 | }
|
55 | ```
|
56 |
|
57 | This will format all `.js` files in the `src` directory. The argument you pass to the CLI
|
58 | is a [glob][glob] and you can pass as many as you wish. You can also pass options.
|
59 |
|
60 | ### Vim
|
61 |
|
62 | Vim users can add the following to their .vimrc:
|
63 |
|
64 | ```
|
65 | autocmd FileType javascript set formatprg=prettier-eslint\ --stdin
|
66 | ```
|
67 |
|
68 | This makes prettier-eslint-cli power the gq command for automatic formatting without any plugins. You can also add the following to your .vimrc to run prettier-eslint-cli when .js files are saved:
|
69 |
|
70 | ```
|
71 | autocmd BufWritePre *.js :normal gggqG
|
72 | ```
|
73 |
|
74 | ### CLI Options
|
75 |
|
76 | ```
|
77 | prettier-eslint --help
|
78 | Usage: prettier-eslint <globs>... [--option-1 option-1-value --option-2]
|
79 |
|
80 | Prefix an option with "no-" to set it to false, such as --no-semi to
|
81 | disable semicolons and --no-eslint-ignore to disable default ignores.
|
82 |
|
83 | Options:
|
84 | -h, --help Show help [boolean]
|
85 | --version Show version number [boolean]
|
86 | --write Edit the file in-place (beware!)
|
87 | [boolean] [default: false]
|
88 | --stdin Read input via stdin [boolean] [default: false]
|
89 | --eslint-ignore Only format matching files even if they are not
|
90 | ignored by .eslintignore. (can use --no-eslint-ignore
|
91 | to disable this) [boolean] [default: true]
|
92 | --list-different Print filenames of files that are different from
|
93 | Prettier + Eslint formatting.
|
94 | [boolean] [default: false]
|
95 | --eslint-path The path to the eslint module to use
|
96 | [default: "./node_modules/eslint"]
|
97 | --eslint-config-path Path to the eslint config to use for eslint --fix
|
98 | --prettier-path The path to the prettier module to use
|
99 | [default: "./node_modules/prettier"]
|
100 | --ignore pattern(s) you wish to ignore (can be used multiple
|
101 | times and includes **/node_modules/** automatically)
|
102 | --log-level, -l The log level to use
|
103 | [choices: "silent", "error", "warn", "info", "debug", "trace"] [default:
|
104 | "warn"]
|
105 | --prettier-last Run prettier last [boolean] [default: false]
|
106 | --use-tabs Indent lines with tabs instead of spaces. [boolean]
|
107 | --print-width Specify the length of line that the printer will wrap
|
108 | on. [number]
|
109 | --tab-width Specify the number of spaces per indentation-level.
|
110 | [number]
|
111 | --trailing-comma Print trailing commas wherever possible.
|
112 |
|
113 | Valid options:
|
114 | - "none" - no trailing commas
|
115 | - "es5" - trailing commas where valid in ES5
|
116 | (objects, arrays, etc)
|
117 | - "all" - trailing commas wherever possible (function
|
118 | arguments) [string] [choices: "none", "es5", "all"]
|
119 | --bracket-spacing Print spaces between brackets in object literals.
|
120 | Can use --no-bracket-spacing for "false" to disable
|
121 | it.
|
122 |
|
123 | Valid options:
|
124 | - true - Example: { foo: bar }
|
125 | - false - Example: {foo: bar} [boolean]
|
126 | --jsx-bracket-same-line Put the > of a multi-line JSX element at the end of
|
127 | the last line instead of being alone on the next line
|
128 | [boolean]
|
129 | --parser Specify which parser to use. [string]
|
130 | --semi Print semicolons at the ends of statements.
|
131 | Can use --no-semi.
|
132 |
|
133 | Valid options:
|
134 | - true - add a semicolon at the end of every
|
135 | statement
|
136 | - false - only add semicolons at the beginning of
|
137 | lines that may introduce ASI failures [boolean]
|
138 | --single-quote Use single quotes instead of double quotes. [boolean]
|
139 | ```
|
140 |
|
141 | #### <globs>
|
142 |
|
143 | Any number of [globs][glob] you wish to use to match the files you wish to format. By default, `glob` will ignore
|
144 | `**/node_modules/**` unless the glob you provide
|
145 | includes the string `node_modules`.
|
146 |
|
147 | #### --write
|
148 |
|
149 | By default `prettier-eslint` will simply log the formatted version to the terminal. If you want to overwrite the file
|
150 | itself (a common use-case) then add `--write`. You should quote your globs, otherwise your terminal will expand the glob before it gets to `prettier-eslint` (which can have unexpected results):
|
151 |
|
152 | ```json
|
153 | {
|
154 | "scripts": {
|
155 | "format": "prettier-eslint --write \"src/**/*.js\""
|
156 | }
|
157 | }
|
158 | ```
|
159 |
|
160 | > **NOTE:** It is recommended that you keep your files under source control and committed
|
161 | > before running `prettier-eslint --write` as it will overwrite your files!
|
162 |
|
163 | #### --list-different
|
164 |
|
165 | Instead of printing the formatted version of the files to the terminal, `prettier-eslint` will log the name of the files that are different from the expected formatting. This can be usefull when using `prettier-eslint` in a version control system hook to inform the committer which files need to be formatted.
|
166 |
|
167 | #### --stdin
|
168 |
|
169 | Accept input via `stdin`. For example:
|
170 |
|
171 | ```
|
172 | echo "var foo = 'bar'" | prettier-eslint --stdin
|
173 | # results in: "var foo = 'bar';" (depending on your eslint config)
|
174 | ```
|
175 |
|
176 | #### --eslint-path
|
177 |
|
178 | Forwarded as the `eslintPath` option to `prettier-eslint`
|
179 |
|
180 | #### --eslint-config-path
|
181 |
|
182 | Resolve eslint config file, parse and forward config object as the `eslintConfig` option to
|
183 | `prettier-eslint`
|
184 |
|
185 | #### --prettier-path
|
186 |
|
187 | Forwarded as the `prettierPath` option to `prettier-eslint`
|
188 |
|
189 | #### --log-level
|
190 |
|
191 | Forwarded as `logLevel` option to `prettier-eslint`
|
192 |
|
193 | #### --no-eslint-ignore
|
194 |
|
195 | Disables application of `.eslintignore` to the files resolved from the glob. By
|
196 | default, `prettier-eslint-cli` will exclude files if they are matched by a
|
197 | `.eslintignore`. Add this flag to disable this behavior.
|
198 |
|
199 | > Note: You can also set the `LOG_LEVEL` environment variable to control logging in `prettier-eslint`
|
200 |
|
201 | #### --prettier-last
|
202 |
|
203 | By default, `prettier-eslint-cli` will run `prettier` first, then `eslint --fix`. This is great if
|
204 | you want to use `prettier`, but override some of the styles you don't like using `eslint --fix`.
|
205 |
|
206 | An alternative approach is to use different tools for different concerns. If you provide the
|
207 | argument `--prettier-last`, it will run `eslint --fix` first, then `prettier`. This allows you to
|
208 | use `eslint` to look for bugs and/or bad practices, and use `prettier` to enforce code style.
|
209 |
|
210 | #### `prettier` options
|
211 |
|
212 | `prettier-eslint-cli` also supports the same command line options as `prettier`.
|
213 |
|
214 | For example: `prettier-eslint --trailing-comma es5`
|
215 |
|
216 | Refer to the [prettier-eslint](https://github.com/prettier/prettier#options) docs for documentation on these options
|
217 |
|
218 | ## Integration
|
219 |
|
220 | Any linter that support ESLint [CLIEngine](http://eslint.org/docs/developer-guide/nodejs-api#cliengine) interface can be integrate with `prettier-eslint`
|
221 |
|
222 | ### Knowed integrated package helpers
|
223 |
|
224 | - [standard-prettier-eslint][standard-prettier-eslint], a helper package for integrate [standard][standard]
|
225 | - [semistandard-prettier-eslint][semistandard-prettier-eslint], a helper package for integrate [semistandard][semistandard]
|
226 |
|
227 | ### Standalone CLI tools based on `prettier-eslint-cli`
|
228 |
|
229 | - [prettier-std-cli][prettier-std-cli] the easy to use CLI version of [standard-prettier-eslint][standard-prettier-eslint]
|
230 | - [prettier-semi-cli][prettier-semi-cli] the easy to use CLI version of [semistandard-prettier-eslint][semistandard-prettier-eslint]
|
231 |
|
232 | ## Related
|
233 |
|
234 | - [prettier-eslint](https://github.com/prettier/prettier-eslint) - the core package
|
235 | - [prettier-eslint-atom](https://github.com/kentcdodds/prettier-eslint-atom) - an atom plugin
|
236 |
|
237 | ## Contributors
|
238 |
|
239 | Thanks goes to these people ([emoji key][emojis]):
|
240 |
|
241 |
|
242 | | [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub>Kent C. Dodds</sub>](https://kentcdodds.com)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Code") [๐](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Documentation") [๐](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=kentcdodds "Tests") | [<img src="https://avatars3.githubusercontent.com/u/3266363?v=3" width="100px;"/><br /><sub>Adam Harris</sub>](https://github.com/aharris88)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Code") [๐](https://github.com/prettier/prettier-eslint-cli/commits?author=aharris88 "Documentation") [๐](#review-aharris88 "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/622118?v=3" width="100px;"/><br /><sub>Eric McCormick</sub>](https://ericmccormick.io)<br />[๐](#review-edm00se "Reviewed Pull Requests") | [<img src="https://avatars.githubusercontent.com/u/12389411?v=3" width="100px;"/><br /><sub>Joel Sequeira</sub>](https://github.com/joelseq)<br />[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=joelseq "Documentation") | [<img src="https://avatars.githubusercontent.com/u/103008?v=3" width="100px;"/><br /><sub>Frank Taillandier</sub>](https://frank.taillandier.me)<br /> | [<img src="https://avatars3.githubusercontent.com/u/292365?v=3" width="100px;"/><br /><sub>Adam Stankiewicz</sub>](http://sheerun.net)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=sheerun "Code") | [<img src="https://avatars3.githubusercontent.com/u/487068?v=3" width="100px;"/><br /><sub>Stephen John Sorensen</sub>](http://www.stephenjohnsorensen.com/)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=spudly "Code") |
|
243 | | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
|
244 | | [<img src="https://avatars0.githubusercontent.com/u/11560964?v=3" width="100px;"/><br /><sub>Gandem</sub>](https://github.com/Gandem)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=Gandem "Tests") | [<img src="https://avatars0.githubusercontent.com/u/129991?v=3" width="100px;"/><br /><sub>Matteo Ronchi</sub>](https://github.com/cef62)<br />[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Acef62 "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=cef62 "Code") | [<img src="https://avatars2.githubusercontent.com/u/61787?v=3" width="100px;"/><br /><sub>Benoรฎt Zugmeyer</sub>](https://github.com/BenoitZugmeyer)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=BenoitZugmeyer "Tests") | [<img src="https://avatars0.githubusercontent.com/u/5038030?v=3" width="100px;"/><br /><sub>Charlike Mike Reagent</sub>](https://i.am.charlike.online)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=tunnckoCore "Tests") | [<img src="https://avatars0.githubusercontent.com/u/10954870?v=3" width="100px;"/><br /><sub>Dion Dirza</sub>](https://github.com/diondirza)<br />[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Adiondirza "Bug reports") | [<img src="https://avatars0.githubusercontent.com/u/3297808?v=3" width="100px;"/><br /><sub>mrm007</sub>](https://github.com/mrm007)<br />[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Amrm007 "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=mrm007 "Code") | [<img src="https://avatars0.githubusercontent.com/u/193238?v=3" width="100px;"/><br /><sub>Jack Franklin</sub>](http://www.jackfranklin.co.uk)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=jackfranklin "Code") |
|
245 | | [<img src="https://avatars0.githubusercontent.com/u/17342435?v=3" width="100px;"/><br /><sub>Ryan Zimmerman</sub>](http://www.ryanzim.com)<br />[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=RyanZim "Documentation") | [<img src="https://avatars3.githubusercontent.com/u/1186409?v=3" width="100px;"/><br /><sub>Paolo Moretti</sub>](http://stackoverflow.com/users/63011)<br />[๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Amoretti "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=moretti "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=moretti "Tests") | [<img src="https://avatars0.githubusercontent.com/u/6242574?v=3" width="100px;"/><br /><sub>bySabi Files</sub>](https://github.com/bySabi)<br />[๐](https://github.com/prettier/prettier-eslint-cli/commits?author=bySabi "Documentation") [๐ง](#tool-bySabi "Tools") | [<img src="https://avatars1.githubusercontent.com/u/554231?v=4" width="100px;"/><br /><sub>Pavel Pertsev</sub>](http://morhetz.com)<br />[๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=morhetz "Code") [โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=morhetz "Tests") | [<img src="https://avatars3.githubusercontent.com/u/13577271?v=4" width="100px;"/><br /><sub>Josh English</sub>](http://www.joshenglish.com)<br />[โ ๏ธ](https://github.com/prettier/prettier-eslint-cli/commits?author=jmenglis "Tests") [๐](https://github.com/prettier/prettier-eslint-cli/issues?q=author%3Ajmenglis "Bug reports") [๐ป](https://github.com/prettier/prettier-eslint-cli/commits?author=jmenglis "Code") [๐](#plugin-jmenglis "Plugin/utility libraries") |
|
246 |
|
247 |
|
248 | This project follows the [all-contributors][all-contributors] specification. Contributions of any kind welcome!
|
249 |
|
250 | ## LICENSE
|
251 |
|
252 | MIT
|
253 |
|
254 | [yarn]: https://yarnpkg.com/
|
255 | [npm]: https://www.npmjs.com/
|
256 | [node]: https://nodejs.org
|
257 | [build-badge]: https://img.shields.io/travis/prettier/prettier-eslint-cli.svg?style=flat-square
|
258 | [build]: https://travis-ci.org/prettier/prettier-eslint-cli
|
259 | [coverage-badge]: https://img.shields.io/codecov/c/github/prettier/prettier-eslint-cli.svg?style=flat-square
|
260 | [coverage]: https://codecov.io/github/prettier/prettier-eslint-cli
|
261 | [version-badge]: https://img.shields.io/npm/v/prettier-eslint-cli.svg?style=flat-square
|
262 | [package]: https://www.npmjs.com/package/prettier-eslint-cli
|
263 | [downloads-badge]: https://img.shields.io/npm/dm/prettier-eslint-cli.svg?style=flat-square
|
264 | [npm-stat]: http://npm-stat.com/charts.html?package=prettier-eslint-cli&from=2016-04-01
|
265 | [license-badge]: https://img.shields.io/npm/l/prettier-eslint-cli.svg?style=flat-square
|
266 | [license]: https://github.com/prettier/prettier-eslint-cli/blob/master/other/LICENSE
|
267 | [prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
268 | [prs]: http://makeapullrequest.com
|
269 | [donate-badge]: https://img.shields.io/badge/$-support-green.svg?style=flat-square
|
270 | [donate]: http://kcd.im/donate
|
271 | [coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
|
272 | [coc]: https://github.com/prettier/prettier-eslint-cli/blob/master/other/CODE_OF_CONDUCT.md
|
273 | [roadmap-badge]: https://img.shields.io/badge/%F0%9F%93%94-roadmap-CD9523.svg?style=flat-square
|
274 | [roadmap]: https://github.com/prettier/prettier-eslint-cli/blob/master/other/ROADMAP.md
|
275 | [examples-badge]: https://img.shields.io/badge/%F0%9F%92%A1-examples-8C8E93.svg?style=flat-square
|
276 | [examples]: https://github.com/prettier/prettier-eslint-cli/blob/master/other/EXAMPLES.md
|
277 | [github-watch-badge]: https://img.shields.io/github/watchers/prettier/prettier-eslint-cli.svg?style=social
|
278 | [github-watch]: https://github.com/prettier/prettier-eslint-cli/watchers
|
279 | [github-star-badge]: https://img.shields.io/github/stars/prettier/prettier-eslint-cli.svg?style=social
|
280 | [github-star]: https://github.com/prettier/prettier-eslint-cli/stargazers
|
281 | [twitter]: https://twitter.com/intent/tweet?text=Check%20out%20prettier-eslint-cli!%20https://github.com/prettier/prettier-eslint-cli%20%F0%9F%91%8D
|
282 | [twitter-badge]: https://img.shields.io/twitter/url/https/github.com/prettier/prettier-eslint-cli.svg?style=social
|
283 | [emojis]: https://github.com/kentcdodds/all-contributors#emoji-key
|
284 | [all-contributors]: https://github.com/kentcdodds/all-contributors
|
285 | [prettier-eslint]: https://github.com/prettier/prettier-eslint
|
286 | [npm scripts]: https://docs.npmjs.com/misc/scripts
|
287 | [package scripts]: https://github.com/kentcdodds/p-s
|
288 | [glob]: https://github.com/isaacs/node-glob
|
289 | [standard-prettier-eslint]: https://github.com/bySabi/standard-prettier-eslint
|
290 | [semistandard-prettier-eslint]: https://github.com/bySabi/semistandard-prettier-eslint
|
291 | [standard]: https://github.com/standard/standard
|
292 | [semistandard]: https://github.com/Flet/semistandard
|
293 | [prettier-std-cli]: https://github.com/bySabi/prettier-std-cli
|
294 | [prettier-semi-cli]: https://github.com/bySabi/prettier-semi-cli
|