Skip to content

Commit

Permalink
feat: extend eslint-config-prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
BPScott committed Dec 19, 2023
1 parent 48ae3d3 commit 51b7c88
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
4 changes: 1 addition & 3 deletions .changeset/old-doors-kiss.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

Add recommended config for the flat config format.

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.
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`.

```js
// eslint.config.js
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
const eslintConfigPrettier = require('eslint-config-prettier');

module.exports = [
// Any other config imports go at the top
eslintPluginPrettierRecommended,
eslintConfigPrettier,
];
```
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,16 @@ This will:

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

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.
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.

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:
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:

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

module.exports = [
// Any other config imports go at the top
eslintPluginPrettierRecommended,
eslintConfigPrettier,
];
```

Expand Down
2 changes: 0 additions & 2 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const eslintPluginN = require('eslint-plugin-n');
const eslintPluginEslintComments = require('@eslint-community/eslint-plugin-eslint-comments');
const eslintPluginEslintPluginRecommended = require('eslint-plugin-eslint-plugin/configs/recommended');
const eslintPluginMdx = require('eslint-plugin-mdx');
const eslintConfigPrettier = require('eslint-config-prettier');
const eslintPluginPrettierRecommended = require('./recommended');

module.exports = [
Expand All @@ -21,7 +20,6 @@ module.exports = [
eslintPluginMdx.flat,
eslintPluginMdx.flatCodeBlocks,
eslintPluginPrettierRecommended,
eslintConfigPrettier,
{
rules: {
'eslint-plugin/report-message-format': ['error', '^[^a-z].*\\.$'],
Expand Down
8 changes: 5 additions & 3 deletions recommended.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const eslintConfigPrettier = require('eslint-config-prettier');
const eslintPluginPrettier = require('./eslint-plugin-prettier');

// This diverges from the legacy format recommended config, as it does not
// extend from the `eslint-config-prettier` ruleset. When using the flat config
// the consumer should add eslint-config-prettier to their own root config.
// Merge the contents of eslint-config-prettier into every
module.exports = {
...eslintConfigPrettier,
plugins: {
...eslintConfigPrettier?.plugins,
prettier: eslintPluginPrettier,
},
rules: {
...eslintConfigPrettier?.rules,
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
Expand Down

0 comments on commit 51b7c88

Please sign in to comment.