Skip to content

Commit 2af9a1a

Browse files
committed
feat: extend eslint-config-prettier
1 parent 48ae3d3 commit 2af9a1a

File tree

4 files changed

+9
-13
lines changed

4 files changed

+9
-13
lines changed

.changeset/old-doors-kiss.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44

55
Add recommended config for the flat config format.
66

7-
If you are using flat config, import the recommended config from `eslint-plugin-prettier/recommended`. Note that in contrast to the legacy recommended config, the flat recommended config does not add `eslint-config-prettier` automatically, consumers will need to explictly add that themselves.
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`.
88

99
```js
1010
// eslint.config.js
1111
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
12-
const eslintConfigPrettier = require('eslint-config-prettier');
1312

1413
module.exports = [
1514
// Any other config imports go at the top
1615
eslintPluginPrettierRecommended,
17-
eslintConfigPrettier,
1816
];
1917
```

README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ npm install --save-dev --save-exact prettier
4343

4444
**_`eslint-plugin-prettier` does not install Prettier or ESLint for you._** _You must install these yourself._
4545

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. You should use [`eslint-config-prettier``](https://github.com/prettier/eslint-config-prettier) to disable all formatting-related ESLint rules.
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.
4747

4848
## Configuration (legacy: `.eslintrc*`)
4949

@@ -65,18 +65,16 @@ This will:
6565

6666
## Configuration (new: `eslint.config.js`)
6767

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 `eslint-plugin-prettier`. Note that unlike the legacy recommended configuration, the flat config does not configure [eslint-config-prettier](https://github.com/prettier/eslint-config-prettier) for you, and you should import and configure that within your own config.
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.
6969

70-
Import `eslint-plugin-prettier/recommended` and `eslint-config-prettier` and add them as the _last_ items in the configuration array in your `eslint.config.js` file so that `eslint-config-prettier` has the opportunity to override other configs:
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:
7171

7272
```js
7373
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
74-
const eslintConfigPrettier = require('eslint-config-prettier');
7574

7675
module.exports = [
7776
// Any other config imports go at the top
7877
eslintPluginPrettierRecommended,
79-
eslintConfigPrettier,
8078
];
8179
```
8280

eslint.config.js

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ const eslintPluginN = require('eslint-plugin-n');
33
const eslintPluginEslintComments = require('@eslint-community/eslint-plugin-eslint-comments');
44
const eslintPluginEslintPluginRecommended = require('eslint-plugin-eslint-plugin/configs/recommended');
55
const eslintPluginMdx = require('eslint-plugin-mdx');
6-
const eslintConfigPrettier = require('eslint-config-prettier');
76
const eslintPluginPrettierRecommended = require('./recommended');
87

98
module.exports = [
@@ -21,7 +20,6 @@ module.exports = [
2120
eslintPluginMdx.flat,
2221
eslintPluginMdx.flatCodeBlocks,
2322
eslintPluginPrettierRecommended,
24-
eslintConfigPrettier,
2523
{
2624
rules: {
2725
'eslint-plugin/report-message-format': ['error', '^[^a-z].*\\.$'],

recommended.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1+
const eslintConfigPrettier = require('eslint-config-prettier');
12
const eslintPluginPrettier = require('./eslint-plugin-prettier');
23

3-
// This diverges from the legacy format recommended config, as it does not
4-
// extend from the `eslint-config-prettier` ruleset. When using the flat config
5-
// the consumer should add eslint-config-prettier to their own root config.
4+
// Merge the contents of eslint-config-prettier into every
65
module.exports = {
6+
...eslintConfigPrettier,
77
plugins: {
8+
...eslintConfigPrettier?.plugins,
89
prettier: eslintPluginPrettier,
910
},
1011
rules: {
12+
...eslintConfigPrettier?.rules,
1113
'prettier/prettier': 'error',
1214
'arrow-body-style': 'off',
1315
'prefer-arrow-callback': 'off',

0 commit comments

Comments
 (0)