Skip to content

Commit a1e5591

Browse files
authored
Turn off problematic rules in recommended config (prepare for next eslint-config-prettier version) (#360)
1 parent f58b6c7 commit a1e5591

File tree

2 files changed

+43
-19
lines changed

2 files changed

+43
-19
lines changed

README.md

+40-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
Runs [Prettier](https://github.com/prettier/prettier) as an [ESLint](http://eslint.org) rule and reports differences as individual ESLint issues.
44

5+
If your desired formatting does not match Prettier’s output, you should use a different tool such as [prettier-eslint](https://github.com/prettier/prettier-eslint) instead.
6+
57
## Sample
68

79
```js
@@ -52,48 +54,68 @@ Then, in your `.eslintrc.json`:
5254

5355
## Recommended Configuration
5456

55-
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.
56-
57-
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.
57+
This plugin works best if you disable all other ESLint rules relating to code formatting, and only enable rules that detect potential bugs. (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.
5858

59-
To integrate this plugin with `eslint-config-prettier`, you can use the `"recommended"` configuration:
59+
This plugin ships with a `plugin:prettier/recommended` config that sets up both the plugin and `eslint-config-prettier` in one go.
6060

6161
1. In addition to the above installation instructions, install `eslint-config-prettier`:
6262

6363
```sh
6464
npm install --save-dev eslint-config-prettier
6565
```
6666

67-
2. Then you need to add `plugin:prettier/recommended` as the last extension in your `.eslintrc.json`:
67+
2. Then you need to add `plugin:prettier/recommended` as the _last_ extension in your `.eslintrc.json`:
6868

6969
```json
7070
{
7171
"extends": ["plugin:prettier/recommended"]
7272
}
7373
```
7474

75-
This does three things:
75+
You can then set Prettier's own options inside a `.prettierrc` file.
7676

77-
- Enables `eslint-plugin-prettier`.
78-
- Sets the `prettier/prettier` rule to `"error"`.
79-
- Extends the `eslint-config-prettier` configuration.
77+
3. Some ESLint plugins (such as [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react)) also contain rules that conflict with Prettier. Add extra exclusions for the plugins you use like so:
78+
79+
```json
80+
{
81+
"extends": [
82+
"plugin:prettier/recommended",
83+
"prettier/flowtype",
84+
"prettier/react"
85+
]
86+
}
87+
```
8088

81-
You can then set Prettier's own options inside a `.prettierrc` file.
89+
For the list of every available exclusion rule set, please see the [readme of eslint-config-prettier](https://github.com/prettier/eslint-config-prettier/blob/master/README.md).
8290

83-
3. In order to support special ESLint plugins (e.g. [eslint-plugin-react](https://github.com/yannickcr/eslint-plugin-react)), add extra exclusions for the plugins you use like so:
91+
Exactly what does `plugin:prettier/recommended` do? Well, this is what it expands to:
8492

8593
```json
8694
{
87-
"extends": [
88-
"plugin:prettier/recommended",
89-
"prettier/flowtype",
90-
"prettier/react",
91-
"prettier/standard"
92-
]
95+
"extends": ["prettier"],
96+
"plugins": ["prettier"],
97+
"rules": {
98+
"prettier/prettier": "error",
99+
"arrow-body-style": "off",
100+
"prefer-arrow-callback": "off"
101+
}
93102
}
94103
```
95104

96-
For the list of every available exclusion rule set, please see the [readme of eslint-config-prettier](https://github.com/prettier/eslint-config-prettier/blob/master/README.md).
105+
- `"extends": ["prettier"]` enables the main config from `eslint-config-prettier`, which turns off some ESLint core rules that conflict with Prettier.
106+
- `"plugins": ["prettier"]` registers this plugin.
107+
- `"prettier/prettier": "error"` turns on the rule provided by this plugin, which runs Prettier from within ESLint.
108+
- `"arrow-body-style": "off"` and `"prefer-arrow-callback": "off"` turns off two ESLint core rules that unfortunately are problematic with this plugin – see the next section.
109+
110+
## `arrow-body-style` and `prefer-arrow-callback` issue
111+
112+
If you use [arrow-body-style](https://eslint.org/docs/rules/arrow-body-style) or [prefer-arrow-callback](https://eslint.org/docs/rules/prefer-arrow-callback) together with the `prettier/prettier` rule from this plugin, you can in some cases end up with invalid code due to a bug in ESLint’s autofix – see [issue #65](https://github.com/prettier/eslint-plugin-prettier/issues/65).
113+
114+
For this reason, it’s recommended to turn off these rules. The `plugin:prettier/recommended` config does that for you.
115+
116+
You _can_ still use these rules together with this plugin if you want, because the bug does not occur _all the time._ But if you do, you need to keep in mind that you might end up with invalid code, where you manually have to insert a missing closing parenthesis to get going again.
117+
118+
If you’re fixing large of amounts of previously unformatted code, consider temporarily disabling the `prettier/prettier` rule and running `eslint --fix` and `prettier --write` separately.
97119

98120
## Options
99121

eslint-plugin-prettier.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ module.exports = {
110110
extends: ['prettier'],
111111
plugins: ['prettier'],
112112
rules: {
113-
'prettier/prettier': 'error'
113+
'prettier/prettier': 'error',
114+
'arrow-body-style': 'off',
115+
'prefer-arrow-callback': 'off'
114116
}
115117
}
116118
},

0 commit comments

Comments
 (0)