-
-
Notifications
You must be signed in to change notification settings - Fork 206
feat: support standard flat file format #765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 5ddbd8e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
WalkthroughSwitches README config examples from CommonJS to ES module flat config with defineConfig and spreads Changes
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
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. 🧪 Early access (Sonnet 4.5): enabledWe 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:
Comment |
There was a problem hiding this 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 in3
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%
<= threshold50%
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%
<= threshold50%
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%
<= threshold50%
None
Workflow ID: wflow_AVO2TNUQ3rQPRKJJ
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
There was a problem hiding this 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
📒 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)
recommended: import('eslint').Linter.Config< | ||
import('eslint').Linter.RulesRecord | ||
>[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
recommended: [ | ||
{ | ||
name: 'prettier/recommended', | ||
plugins: { | ||
get prettier() { | ||
return eslintPluginPrettier; | ||
}, | ||
}, | ||
rules: { | ||
'prettier/prettier': 'error', | ||
'arrow-body-style': 'off', | ||
'prefer-arrow-callback': 'off', | ||
}, | ||
}, | ||
}, | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 I'm going to close this, as I'll likely end up re-implementing it myself once that time for major version bumps comes. |
Changes
Issues
Notes
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.eslint-plugin-prettier
.recommended
config to be used withdefineConfig
ineslint.config.js
.eslint-plugin-prettier.js
: Definesrecommended
config as an array with plugins and rules.eslint-plugin-prettier.d.ts
: Declaresconfigs
object withrecommended
config.README.md
to reflect new configuration method usingdefineConfig
and...prettier.configs.recommended
.This description was created by
for 28a631e. You can customize this summary. It will automatically update as commits are pushed.
Summary by CodeRabbit
New Features
Documentation
Chores