UNPKG

3.89 kBMarkdownView Raw
1# eslint-plugin-prettier [![Build Status](https://travis-ci.org/prettier/eslint-plugin-prettier.svg?branch=master)](https://travis-ci.org/prettier/eslint-plugin-prettier)
2
3Runs [Prettier](https://github.com/prettier/prettier) as an [ESLint](http://eslint.org) rule and reports differences as individual ESLint issues.
4
5## Sample
6
7```js
8error: Insert `,` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:22:25:
9 20 | import {
10 21 | observeActiveEditorsDebounced,
11> 22 | editorChangesDebounced
12 | ^
13 23 | } from './debounced';;
14 24 |
15 25 | import {observableFromSubscribeFunction} from '../commons-node/event';
16
17
18error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.js:23:21:
19 21 | observeActiveEditorsDebounced,
20 22 | editorChangesDebounced
21> 23 | } from './debounced';;
22 | ^
23 24 |
24 25 | import {observableFromSubscribeFunction} from '../commons-node/event';
25 26 | import {cacheWhileSubscribed} from '../commons-node/observable';
26
27
282 errors found.
29```
30
31> `./node_modules/.bin/eslint --format codeframe pkg/commons-atom/ActiveEditorRegistry.js` (code from [nuclide](https://github.com/facebook/nuclide)).
32
33## Installation
34
35```sh
36npm install --save-dev prettier eslint-plugin-prettier
37```
38
39**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._
40
41Then, in your `.eslintrc.json`:
42
43```json
44{
45 "plugins": [
46 "prettier"
47 ],
48 "rules": {
49 "prettier/prettier": "error"
50 }
51}
52```
53
54## Options
55
56* The first option:
57 - Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#options). Example:
58
59 ```json
60 "prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
61 ```
62
63 - Or the string `"fb"` may be used to set "Facebook style" defaults:
64
65 ```json
66 "prettier/prettier": ["error", "fb"]
67 ```
68
69 Equivalent to:
70
71 ```json
72 "prettier/prettier": ["error", {
73 "singleQuote": true,
74 "trailingComma": "all",
75 "bracketSpacing": false,
76 "jsxBracketSameLine": true,
77 "parser": "flow"
78 }]
79 ```
80 NB: This option will merge and override any config set with `.prettierrc` files (for Prettier < 1.7.0, [config files are ignored](https://github.com/prettier/eslint-plugin-prettier/issues/46))
81
82* The second option:
83
84 - A string with a pragma that triggers this rule. By default, this rule applies to all files. However, if you set a pragma (this option), only files with that pragma in the heading docblock will be checked. All pragmas must start with `@`. Example:
85
86 ```json
87 "prettier/prettier": ["error", null, "@prettier"]
88 ```
89
90 Only files with `@prettier` in the heading docblock will be checked:
91
92 ```js
93 /** @prettier */
94
95 console.log(1 + 2 + 3);
96 ```
97
98 Or:
99
100 ```js
101 /**
102 * @prettier
103 */
104
105 console.log(4 + 5 + 6);
106 ```
107
108 _This option is useful if you're migrating a large codebase and already use pragmas like `@flow`._
109
110* The rule is autofixable -- if you run `eslint` with the `--fix` flag, your code will be formatted according to `prettier` style.
111
112---
113
114This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect patterns in the AST. (If another active ESLint rule disagrees with `prettier` about how code should be formatted, it will be impossible to avoid lint errors.) You can use [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) to disable all formatting-related ESLint rules. If your desired formatting does not match the `prettier` output, you should use a different tool such as [prettier-eslint](https://github.com/prettier/prettier-eslint) instead.
115
116## Contributing
117
118See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)
119
\No newline at end of file