Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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
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',
},
},
},
],
Comment on lines +134 to +148
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

Keep the legacy .eslintrc config intact.

Replacing configs.recommended with a flat-config array means extends: ["plugin:prettier/recommended"] (the documented legacy path) now loads an array whose entries use the flat plugins map. Legacy .eslintrc expects a single config object with plugins: string[], so this is a silent breaking change. Please preserve the existing object-based configs.recommended for legacy users and expose the flat config under a new key (e.g. configs['flat/recommended']) or via another property that flat-config consumers can spread.

🤖 Prompt for AI Agents
eslint-plugin-prettier.js lines 134-148: the change replaced configs.recommended
with a flat-config array which breaks legacy .eslintrc consumers expecting a
single config object with plugins as string[]; restore a legacy object-based
configs.recommended that contains name, plugins as an array of plugin names, and
rules as before, and expose the flat-config array under a new key (e.g.
configs['flat/recommended'] or another property) so flat-config consumers can
still import/spread it; ensure both keys are exported and update any tests or
docs referencing the new key.

},
rules: {
prettier: {
Expand Down