Skip to content

Conversation

peaklabs-dev
Copy link

@peaklabs-dev peaklabs-dev commented Sep 28, 2025

Changes

  • feat: Adds support for standard flat file format.

Issues

Notes

  • This PR is similar to (PR): add config flat #759 but does not add a new rule, it simply extends the existing code to support the standard flat-file format as well.
  • I tested both the current implementation and the standard implementation and they both still work.
  • I understand your comment about not having 2 ways to do things but I think we should recommend this method moving forward as it is consistent with every other plugin. The old method can be deprecated at some point much later or never.

Edit: I forgot that we support non-flat config files, which will be broken by this change. Perhaps this PR would be better suited for a major version. I think it would make sense to drop support for ESLint 8.x (end of life for over 1 year), none flat config files (or we could allow non flat config options if ESLINT_USE_FLAT_CONFIG is set) or drop soon with ESLint 10 on the way https://eslint.org/blog/2023/10/flat-config-rollout-plans/#eslintrc-removed-in-eslint-v10.0.0 and maybe add these PRs #763 and #761 as well, which make sense for a new major version. The current way for the flat config files could then be marked as deprecated but still for most users with flat config this would not require any changes and would be a smooth upgrade (it still works, just deprecated).


Important

Adds support for standard flat file format in eslint-plugin-prettier with updated configuration and documentation.

  • Behavior:
    • Adds support for standard flat file format in eslint-plugin-prettier.
    • Updates recommended config to be used with defineConfig in eslint.config.js.
  • Configuration:
    • eslint-plugin-prettier.js: Defines recommended config as an array with plugins and rules.
    • eslint-plugin-prettier.d.ts: Declares configs object with recommended config.
  • Documentation:
    • Updates README.md to reflect new configuration method using defineConfig and ...prettier.configs.recommended.

This description was created by Ellipsis for 28a631e. You can customize this summary. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • New Features

    • Adds a named "prettier/recommended" config compatible with modern ESLint flat config.
    • Exposes a public recommended config via plugin configs for direct import/spread in user configs.
    • Updates TypeScript typings to include the recommended config for improved editor/build support.
  • Documentation

    • Updates configuration examples to ES module style (defineConfig) and replaces legacy CommonJS/plugin usage with modern imports and preset spreading.
  • Chores

    • Adds a changeset indicating a minor release and support for the flat config format.

Copy link

changeset-bot bot commented Sep 28, 2025

🦋 Changeset detected

Latest commit: 5ddbd8e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
eslint-plugin-prettier Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

coderabbitai bot commented Sep 28, 2025

Walkthrough

Switches README config examples from CommonJS to ES module flat config with defineConfig and spreads prettier.configs.recommended. Adds types for configs.recommended in the .d.ts. Changes runtime configs.recommended from an object to an array exposing a named flat config with an inline plugin getter.

Changes

Cohort / File(s) Summary
Docs: ES module flat config usage
README.md
Replaces CommonJS example with ESM import/export, introduces defineConfig from eslint/config, imports the plugin as default, and uses spread of ...prettier.configs.recommended.
Type declarations for flat config
eslint-plugin-prettier.d.ts
Extends exported plugin type to include configs.recommended: import('eslint').Linter.Config<import('eslint').Linter.RulesRecord>[], preserving export = eslintPluginPrettier.
Runtime recommended config shape
eslint-plugin-prettier.js
Converts configs.recommended from a single object to an array with a named config entry (name: 'prettier/recommended'), provides an inline plugins getter that returns the plugin, and preserves the rules set.
Release metadata
.changeset/*
Adds a changeset declaring a minor release and noting support for the standard flat file format.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Dev as Developer
  participant ESLint as ESLint (flat config)
  participant Plugin as eslint-plugin-prettier

  Dev->>ESLint: import prettier from 'eslint-plugin-prettier'
  Dev->>ESLint: defineConfig(..., ...prettier.configs.recommended, {...})
  ESLint->>Plugin: Resolve configs.recommended (array)
  Note right of Plugin #DFF2E1: Returns [ { name: "prettier/recommended", plugins: { get prettier() { ... } }, rules: {...} } ]
  ESLint->>ESLint: Merge named config into final config
  ESLint->>Dev: Lints using merged config
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • JounQin

Poem

I thump with glee at configs spread,
From nests of CJS we hop ahead.
A flat trail shines, recommended true,
Plugins peek out and rules pass through.
defineConfig—my little hop of cheer. 🐇✨

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title “feat: support standard flat file format” clearly and concisely summarizes the primary change—which is adding support for the standard flat-file ESLint configuration API—using conventional commit style without extraneous detail. It accurately reflects the main objective of the PR and would be immediately understood by teammates scanning the history.
Linked Issues Check ✅ Passed The PR fully addresses the objectives of issue #764 by exposing a configs.recommended array in the plugin code (eslint-plugin-prettier.js), defining its type in eslint-plugin-prettier.d.ts, and updating README.md to illustrate using defineConfig with ...prettier.configs.recommended, thereby enabling the standard flat-file import pattern.
Out of Scope Changes Check ✅ Passed All modifications—including the JavaScript implementation, TypeScript declarations, documentation updates, and changeset metadata—directly support adding standard flat-file configuration support as defined by the linked issue, and there are no unrelated alterations outside that scope.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

Important

Looks good to me! 👍

Reviewed everything up to 28a631e in 54 seconds. Click for details.
  • Reviewed 80 lines of code in 3 files
  • Skipped 0 files when reviewing.
  • Skipped posting 3 draft comments. View those below.
  • Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. README.md:80
  • Draft comment:
    The README update for flat config is clear. Note that the recommended config is now an array that must be spread using the spread operator. Make sure users understand this change from the legacy object format.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
2. eslint-plugin-prettier.d.ts:3
  • Draft comment:
    The type definition now marks 'configs.recommended' as an array. This correctly reflects the flat config format and matches the implementation.
  • Reason this comment was not posted:
    Confidence changes required: 0% <= threshold 50% None
3. eslint-plugin-prettier.js:133
  • Draft comment:
    The recommended config is now provided as an array with a name and lazy-loaded plugin getter. Removing the legacy 'extends: ["prettier"]' is intentional for flat config support, but ensure that legacy users or documentation mention this migration if needed.
  • Reason this comment was not posted:
    Confidence changes required: 33% <= threshold 50% None

Workflow ID: wflow_AVO2TNUQ3rQPRKJJ

You can customize Ellipsis by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between befda88 and 28a631e.

📒 Files selected for processing (3)
  • README.md (1 hunks)
  • eslint-plugin-prettier.d.ts (1 hunks)
  • eslint-plugin-prettier.js (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-06-17T07:50:43.759Z
Learnt from: JounQin
PR: prettier/eslint-plugin-prettier#743
File: test/prettier.mjs:28-35
Timestamp: 2025-06-17T07:50:43.759Z
Learning: In the eslint-plugin-prettier test file, the pattern `const ESLint = eslintUnsupportedApi.FlatESLint ?? eslint.ESLint;` works correctly even though `eslint` is declared later with `var eslint;` because the hoisted declaration makes `eslint` available throughout the file, and `eslintUnsupportedApi.FlatESLint` is always truthy when this code executes, so the `eslint.ESLint` fallback is never evaluated.

Applied to files:

  • eslint-plugin-prettier.d.ts
🧬 Code graph analysis (2)
eslint-plugin-prettier.d.ts (1)
eslint-plugin-prettier.js (1)
  • eslintPluginPrettier (131-308)
eslint-plugin-prettier.js (1)
test/prettier.mjs (3)
  • config (547-550)
  • runFixture (498-582)
  • name (108-108)

Comment on lines +5 to +7
recommended: import('eslint').Linter.Config<
import('eslint').Linter.RulesRecord
>[];
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.

Comment on lines +134 to +148
recommended: [
{
name: 'prettier/recommended',
plugins: {
get prettier() {
return eslintPluginPrettier;
},
},
rules: {
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
},
},
],
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.

@BPScott
Copy link
Member

BPScott commented Sep 29, 2025

I forgot that we support non-flat config files, which will be broken by this change. Perhaps this PR would be better suited for a major version.

Indeed this is a breaking change.

See #758 (comment) and #759 (comment) for extra flat-config context.

At some point we will do a major version bump to drop support for ESlint v8, node 14 and 16 and remove the need for @types/eslint. However at this point in time this plugin is stable, it doesn't need any new features, and thus this legacy support isn't getting in the way. Once there is a new feature that requires these major updates we'll make them.

I'm going to close this, as I'll likely end up re-implementing it myself once that time for major version bumps comes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support standard flat file format
2 participants