Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/eleven-foxes-bet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-prettier": minor
---

Add support for the standard flat file format.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@ 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 both `eslint-plugin-prettier` and [`eslint-config-prettier`](https://github.com/prettier/eslint-config-prettier) in one go.
For [flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files-new), this plugin ships with a `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 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:
Import `eslint-plugin-prettier` and use `...prettier.configs.recommended` as the _last_ item in your `defineConfig` so that `eslint-config-prettier` has the opportunity to override other configs:

```js
const eslintPluginPrettierRecommended = require('eslint-plugin-prettier/recommended');
import prettier from 'eslint-plugin-prettier';
import { defineConfig } from 'eslint/config';

module.exports = [
export default defineConfig(
// Any other config imports go at the top
eslintPluginPrettierRecommended,
];
...prettier.configs.recommended,
);
```

This will:
Expand Down
8 changes: 7 additions & 1 deletion eslint-plugin-prettier.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { ESLint } from 'eslint';

declare const eslintPluginPrettier: ESLint.Plugin;
declare const eslintPluginPrettier: ESLint.Plugin & {
configs: {
recommended: import('eslint').Linter.Config<
import('eslint').Linter.RulesRecord
>[];
Comment on lines +5 to +7
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix the flat config typing for configs.recommended.

configs.recommended now returns a flat-config array whose entries use the flat shape (plugins object with actual plugin values). Typing it as Linter.Config<RulesRecord>[] is wrong—legacy configs expect plugins: string[], so consumers will get type errors when they spread this into defineConfig (which expects Linter.FlatConfig). Please change the declaration to import('eslint').Linter.FlatConfig[] (or an equivalent alias) to reflect the real runtime shape.

-    recommended: import('eslint').Linter.Config<
-      import('eslint').Linter.RulesRecord
-    >[];
+    recommended: import('eslint').Linter.FlatConfig[];
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
recommended: import('eslint').Linter.Config<
import('eslint').Linter.RulesRecord
>[];
recommended: import('eslint').Linter.FlatConfig[];
🤖 Prompt for AI Agents
In eslint-plugin-prettier.d.ts around lines 5 to 7, configs.recommended is
incorrectly typed as Linter.Config<RulesRecord>[]; replace that type with
import('eslint').Linter.FlatConfig[] (or an equivalent alias) so the declaration
reflects the flat-config runtime shape (plugins object with actual plugin
values) and avoids type errors when consumers spread it into defineConfig.

};
};

export = eslintPluginPrettier;
22 changes: 14 additions & 8 deletions eslint-plugin-prettier.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,21 @@ function reportDifference(context, difference) {
const eslintPluginPrettier = {
meta: { name, version },
configs: {
recommended: {
extends: ['prettier'],
plugins: ['prettier'],
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
recommended: [
{
name: 'prettier/recommended',
plugins: {
get prettier() {
return eslintPluginPrettier;
},
},
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
},
},
],
},
rules: {
prettier: {
Expand Down