Skip to content

Commit e529b60

Browse files
azznot-an-aardvark
authored andcommitted
New: Add 'recommended' configuration (#73)
1 parent 4335b08 commit e529b60

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

README.md

+37-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ error: Delete `;` (prettier/prettier) at pkg/commons-atom/ActiveEditorRegistry.j
3333
## Installation
3434

3535
```sh
36-
npm install --save-dev prettier eslint-plugin-prettier
36+
npm install --save-dev eslint-plugin-prettier
37+
npm install --save-dev --save-exact prettier
3738
```
3839

3940
**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._
@@ -51,10 +52,44 @@ Then, in your `.eslintrc.json`:
5152
}
5253
```
5354

55+
## Recommended Configuration
56+
57+
This 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.
58+
59+
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.
60+
61+
To integrate this plugin with `eslint-config-prettier`, you can use the `"recommended"` configuration:
62+
63+
1. In addition to the above installation instructions, install `eslint-config-prettier`:
64+
65+
```sh
66+
npm install --save-dev eslint-config-prettier
67+
```
68+
69+
2. Then all you need in your `.eslintrc.json` is:
70+
71+
```json
72+
{
73+
"extends": [
74+
"plugin:prettier/recommended"
75+
]
76+
}
77+
```
78+
79+
This does three things:
80+
81+
1. Enables `eslint-plugin-prettier`.
82+
2. Sets the `prettier/prettier` rule to `"error"`.
83+
3. Extends the `eslint-config-prettier` configuration.
84+
85+
You can then set Prettier's own options inside a `.prettierrc` file.
86+
5487
## Options
5588

89+
> Note: While it is possible to pass options to Prettier via your ESLint configuration file, it is not recommended because editor extensions such as `prettier-atom` and `prettier-vscode` **will** read [`.prettierrc`](https://prettier.io/docs/en/configuration.html), but **won't** read settings from ESLint, which can lead to an inconsistent experience.
90+
5691
* The first option:
57-
- Objects are passed directly to Prettier as [options](https://github.com/prettier/prettier#options). Example:
92+
- Objects are passed directly to Prettier as [options](https://prettier.io/docs/en/options.html). Example:
5893

5994
```json
6095
"prettier/prettier": ["error", {"singleQuote": true, "parser": "flow"}]
@@ -111,8 +146,6 @@ Then, in your `.eslintrc.json`:
111146

112147
---
113148

114-
This 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-
116149
## Contributing
117150

118151
See [CONTRIBUTING.md](https://github.com/prettier/eslint-plugin-prettier/blob/master/CONTRIBUTING.md)

eslint-plugin-prettier.js

+9
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ function reportReplace(context, offset, deleteText, insertText) {
289289
module.exports = {
290290
showInvisibles,
291291
generateDifferences,
292+
configs: {
293+
recommended: {
294+
extends: ['prettier'],
295+
plugins: ['prettier'],
296+
rules: {
297+
'prettier/prettier': 'error'
298+
}
299+
}
300+
},
292301
rules: {
293302
prettier: {
294303
meta: {

0 commit comments

Comments
 (0)