You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
recommended.js is a flat config version of the recommended config.
It follows the pattern of the legacy recommended config by automatically
configuring eslint-config-prettier.
Add recommended config for the flat config format.
6
+
7
+
If you are using flat config, import the recommended config from `eslint-plugin-prettier/recommended`. Like the legacy format recommended config, this automatically includes the contents of `eslint-config-prettier`.
**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._**_You must install these yourself._
45
45
46
-
Then, in your `.eslintrc.json`:
46
+
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. Our recommended configuration automatically enables [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) to disable all formatting-related ESLint rules.
47
+
48
+
## Configuration (legacy: `.eslintrc*`)
49
+
50
+
For [legacy configuration](https://eslint.org/docs/latest/use/configure/configuration-files), this plugin ships with a `plugin:prettier/recommended` config that sets up both `eslint-plugin-prettier` and [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) in one go.
51
+
52
+
Add `plugin:prettier/recommended` as the _last_ item in the extends array in your `.eslintrc*` config file, so that `eslint-config-prettier` has the opportunity to override other configs:
47
53
48
54
```json
49
55
{
50
-
"plugins": ["prettier"],
51
-
"rules": {
52
-
"prettier/prettier": "error"
53
-
}
56
+
"extends": ["plugin:prettier/recommended"]
54
57
}
55
58
```
56
59
57
-
## Recommended Configuration
58
-
59
-
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.
60
-
61
-
This plugin ships with a `plugin:prettier/recommended` config that sets up both the plugin and `eslint-config-prettier` in one go.
62
-
63
-
1. In addition to the above installation instructions, install `eslint-config-prettier`:
60
+
This will:
64
61
65
-
```sh
66
-
npm install --save-dev eslint-config-prettier
67
-
```
62
+
- Enable the `prettier/prettier` rule.
63
+
- Disable the `arrow-body-style` and `prefer-arrow-callback` rules which are problematic with this plugin - see the below for why.
64
+
- Enable the `eslint-config-prettier` config which will turn off ESLint rules that conflict with Prettier.
68
65
69
-
2. Then you need to add `plugin:prettier/recommended` as the _last_ extension in your `.eslintrc.json`:
66
+
## Configuration (new: `eslint.config.js`)
70
67
71
-
```json
72
-
{
73
-
"extends": ["plugin:prettier/recommended"]
74
-
}
75
-
```
68
+
For [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new), this plugin ships with an `eslint-plugin-prettier/recommended` config that sets up both `eslint-plugin-prettier` and [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) in one go.
76
69
77
-
You can then set Prettier's own options inside a `.prettierrc` file.
70
+
Import `eslint-plugin-prettier/recommended` and add it as the _last_ item in the configuration array in your `eslint.config.js` file so that `eslint-config-prettier` has the opportunity to override other configs:
78
71
79
-
Exactly what does `plugin:prettier/recommended` do? Well, this is what it expands to:
-`"extends": ["prettier"]` enables the config from `eslint-config-prettier`, which turns off some ESLint rules that conflict with Prettier.
94
-
-`"plugins": ["prettier"]` registers this plugin.
95
-
-`"prettier/prettier": "error"` turns on the rule provided by this plugin, which runs Prettier from within ESLint.
96
-
-`"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.
81
+
This will:
82
+
83
+
- Enable the `prettier/prettier` rule.
84
+
- Disable the `arrow-body-style` and `prefer-arrow-callback` rules which are problematic with this plugin - see the below for why.
85
+
- Enable the `eslint-config-prettier` config which will turn off ESLint rules that conflict with Prettier.
0 commit comments