Skip to content

feat(types): prefer Config over FlatConfig when they're equal #674

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

Merged

Conversation

irsooti
Copy link
Contributor

@irsooti irsooti commented Aug 1, 2024

Hello,

the type FlatConfig has been replaced with Config, according to the deprecation warning.
image

I just changed the type with the suggested one.

Cheers!

Summary by CodeRabbit

  • New Features
    • Improved type system to prefer the Config type over FlatConfig when both are equivalent in the configuration.
  • Documentation
    • Added a changeset documenting the minor update to the configuration types.

Copy link

changeset-bot bot commented Aug 1, 2024

🦋 Changeset detected

Latest commit: 42abb5d

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

@MartinX3
Copy link

MartinX3 commented Aug 11, 2024

@irsooti I tried your change but maybe it's because I use the eslint.config.ts since ESLint 9.9.0.

eslint.config.ts:29:3 - error TS2345: Argument of type 'Config<RulesRecord>' is not assignable to parameter of type 'ConfigWithExtends'.
  Types of property 'languageOptions' are incompatible.
    Type 'import("path/node_modules/.pnpm/@types+eslint@9.6.0/node_modules/@types/eslint/index").Linter.LanguageOptions | undefined' is not assignable to type 'import("path/node_modules/.pnpm/@typescript-eslint+utils@8.0.1_eslint@9.9.0_jiti@1.21.6__typescript@5.5.4/node_modules/@typescript-eslint/utils/dist/ts-eslint/Config").FlatConfig.LanguageOptions | undefined'.
      Type 'import("path/node_modules/.pnpm/@types+eslint@9.6.0/node_modules/@types/eslint/index").Linter.LanguageOptions' is not assignable to type 'import("path/node_modules/.pnpm/@typescript-eslint+utils@8.0.1_eslint@9.9.0_jiti@1.21.6__typescript@5.5.4/node_modules/@typescript-eslint/utils/dist/ts-eslint/Config").FlatConfig.LanguageOptions'.
        Types of property 'globals' are incompatible.
          Type 'Globals | undefined' is not assignable to type 'GlobalsConfig | undefined'.
            Type 'Globals' is not assignable to type 'GlobalsConfig'.
              'string' index signatures are incompatible.
                Type 'GlobalConf' is not assignable to type 'GlobalVariableOption'.
                  Type '"readable"' is not assignable to type 'GlobalVariableOption'.

Edit:
It seems to work using Readonly<Linter.RulesRecord> instead of Linter.Config like used here
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/136deed9a5c0adaea7bc7674783bb52608673d05/types/eslint__js/index.d.ts#L5

@JounQin
Copy link
Member

JounQin commented Jan 15, 2025

It seems to work using Readonly<Linter.RulesRecord> instead of Linter.Config like used here

That's not same thing, RulesRecord only include rules, but recommended.js is different.

module.exports = {
...eslintConfigPrettier,
plugins: {
...eslintConfigPrettier.plugins,
prettier: eslintPluginPrettier,
},
rules: {
...eslintConfigPrettier.rules,
'prettier/prettier': 'error',
'arrow-body-style': 'off',
'prefer-arrow-callback': 'off',
},
};

@JounQin
Copy link
Member

JounQin commented Jan 15, 2025

This would be a breaking change for eslint v8 users.

@MartinX3
Copy link

It's working for me without my workaround since some time.

@JounQin JounQin force-pushed the feat/deprecate-flat-config-to-config branch from 7cc0835 to 4d2e086 Compare May 4, 2025 05:54
Copy link

coderabbitai bot commented May 4, 2025

Walkthrough

A new changeset file was added to document a minor update to the eslint-plugin-prettier package. The update introduces a conditional type alias, IfEqual, within the type declarations. This alias is used to determine if Linter.Config and Linter.FlatConfig are equivalent, and accordingly sets the type of recommendedConfig to prefer Config when both types are equal. No changes were made to the declarations of exported or public entities beyond the type alias and the updated type for recommendedConfig.

Changes

File(s) Change Summary
.changeset/lucky-badgers-judge.md Added a changeset documenting a minor update to the eslint-plugin-prettier package regarding type preference.
recommended.d.ts Introduced IfEqual type alias; updated recommendedConfig type to use conditional type logic for type equality.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant TypeSystem

    Developer->>TypeSystem: Reference recommendedConfig
    TypeSystem->>TypeSystem: Evaluate IfEqual<Linter.Config, Linter.FlatConfig, Linter.Config, Linter.FlatConfig>
    alt Types are equal
        TypeSystem-->>Developer: recommendedConfig is Linter.Config
    else Types are not equal
        TypeSystem-->>Developer: recommendedConfig is Linter.FlatConfig
    end
Loading

Poem

A hop and a skip, a type check anew,
Where Configs and FlatConfigs meet in review.
If equal, we cheer, and Config takes the lead,
If not, FlatConfig fulfills every need.
With changesets noted and types all aligned,
This rabbit approves—what a clever design!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e37575 and 42abb5d.

📒 Files selected for processing (2)
  • .changeset/lucky-badgers-judge.md (1 hunks)
  • recommended.d.ts (1 hunks)
🔇 Additional comments (2)
recommended.d.ts (1)

10-10: The type condition appropriately handles ESLint version compatibility.

This change implements the preference for Config over FlatConfig when they're equal, aligning with ESLint's deprecation notice while maintaining backward compatibility with both ESLint v8 and v9.

.changeset/lucky-badgers-judge.md (1)

1-5: Appropriate changeset documentation for a minor version change.

The changeset correctly documents this as a minor version change with a clear description that matches the implementation. This ensures users are properly informed about the change in the release notes.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@JounQin JounQin changed the title feat: change type from deprecated FlatConfig to Config feat: prefer Config over FlatConfig when they're equal May 4, 2025
@JounQin JounQin changed the title feat: prefer Config over FlatConfig when they're equal feat(types): prefer Config over FlatConfig when they're equal May 4, 2025
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9e37575 and c9a7436.

📒 Files selected for processing (2)
  • .changeset/lucky-badgers-judge.md (1 hunks)
  • recommended.d.ts (1 hunks)
🔇 Additional comments (1)
.changeset/lucky-badgers-judge.md (1)

1-6: Changelog entry looks good

The changeset correctly records a minor version bump and concisely describes the type-system tweak. No action required.

@JounQin JounQin force-pushed the feat/deprecate-flat-config-to-config branch from c9a7436 to 89704c3 Compare May 4, 2025 05:59
@JounQin JounQin force-pushed the feat/deprecate-flat-config-to-config branch from 89704c3 to 42abb5d Compare May 4, 2025 06:13
@prettier prettier deleted a comment from coderabbitai bot May 4, 2025
@JounQin
Copy link
Member

JounQin commented May 4, 2025

@coderabbitai full review

Copy link

coderabbitai bot commented May 4, 2025

✅ Actions performed

Full review triggered.

@JounQin JounQin merged commit 6fe0c90 into prettier:main May 4, 2025
9 checks passed
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 4, 2025
| datasource | package                | from  | to    |
| ---------- | ---------------------- | ----- | ----- |
| npm        | eslint-plugin-prettier | 5.2.3 | 5.3.1 |


## [v5.3.1](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#531)

##### Patch Changes

-   [#734](prettier/eslint-plugin-prettier#734) [`dcf2c80`](prettier/eslint-plugin-prettier@dcf2c80) Thanks [@JounQin](https://github.com/JounQin)! - ci: enable `NPM_CONFIG_PROVENANCE` env


## [v5.3.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#530)

##### Minor Changes

-   [#674](prettier/eslint-plugin-prettier#674) [`6fe0c90`](prettier/eslint-plugin-prettier@6fe0c90) Thanks [@irsooti](https://github.com/irsooti)! - feat(types): prefer `Config` over `FlatConfig` when they're equal


## [v5.2.6](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#526)

##### Patch Changes

-   [#723](prettier/eslint-plugin-prettier#723) [`1451176`](prettier/eslint-plugin-prettier@1451176) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): bump `synckit` to `v0.11.0`


## [v5.2.5](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#525)

##### Patch Changes

-   [#721](prettier/eslint-plugin-prettier#721) [`4f5513d`](prettier/eslint-plugin-prettier@4f5513d) Thanks [@JounQin](https://github.com/JounQin)! - fix: clarify correct `eslint-config-prettier` peer range


## [v5.2.4](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#524)

##### Patch Changes

-   [#715](prettier/eslint-plugin-prettier#715) [`b8cfe56`](prettier/eslint-plugin-prettier@b8cfe56) Thanks [@JounQin](https://github.com/JounQin)! - chore: hourcekeeping, bump all (dev) deps
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 4, 2025
| datasource | package                | from  | to    |
| ---------- | ---------------------- | ----- | ----- |
| npm        | eslint-plugin-prettier | 5.2.3 | 5.3.1 |


## [v5.3.1](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#531)

##### Patch Changes

-   [#734](prettier/eslint-plugin-prettier#734) [`dcf2c80`](prettier/eslint-plugin-prettier@dcf2c80) Thanks [@JounQin](https://github.com/JounQin)! - ci: enable `NPM_CONFIG_PROVENANCE` env


## [v5.3.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#530)

##### Minor Changes

-   [#674](prettier/eslint-plugin-prettier#674) [`6fe0c90`](prettier/eslint-plugin-prettier@6fe0c90) Thanks [@irsooti](https://github.com/irsooti)! - feat(types): prefer `Config` over `FlatConfig` when they're equal


## [v5.2.6](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#526)

##### Patch Changes

-   [#723](prettier/eslint-plugin-prettier#723) [`1451176`](prettier/eslint-plugin-prettier@1451176) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): bump `synckit` to `v0.11.0`


## [v5.2.5](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#525)

##### Patch Changes

-   [#721](prettier/eslint-plugin-prettier#721) [`4f5513d`](prettier/eslint-plugin-prettier@4f5513d) Thanks [@JounQin](https://github.com/JounQin)! - fix: clarify correct `eslint-config-prettier` peer range


## [v5.2.4](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#524)

##### Patch Changes

-   [#715](prettier/eslint-plugin-prettier#715) [`b8cfe56`](prettier/eslint-plugin-prettier@b8cfe56) Thanks [@JounQin](https://github.com/JounQin)! - chore: hourcekeeping, bump all (dev) deps
@irsooti irsooti deleted the feat/deprecate-flat-config-to-config branch May 5, 2025 07:58
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 10, 2025
| datasource | package                | from  | to    |
| ---------- | ---------------------- | ----- | ----- |
| npm        | eslint-plugin-prettier | 5.2.3 | 5.4.0 |


## [v5.4.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#540)

##### Minor Changes

-   [#736](prettier/eslint-plugin-prettier#736) [`59a0cae`](prettier/eslint-plugin-prettier@59a0cae) Thanks [@yashtech00](https://github.com/yashtech00)! - refactor: migrate `worker.js` to `worker.mjs`


## [v5.3.1](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#531)

##### Patch Changes

-   [#734](prettier/eslint-plugin-prettier#734) [`dcf2c80`](prettier/eslint-plugin-prettier@dcf2c80) Thanks [@JounQin](https://github.com/JounQin)! - ci: enable `NPM_CONFIG_PROVENANCE` env


## [v5.3.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#530)

##### Minor Changes

-   [#674](prettier/eslint-plugin-prettier#674) [`6fe0c90`](prettier/eslint-plugin-prettier@6fe0c90) Thanks [@irsooti](https://github.com/irsooti)! - feat(types): prefer `Config` over `FlatConfig` when they're equal


## [v5.2.6](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#526)

##### Patch Changes

-   [#723](prettier/eslint-plugin-prettier#723) [`1451176`](prettier/eslint-plugin-prettier@1451176) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): bump `synckit` to `v0.11.0`


## [v5.2.5](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#525)

##### Patch Changes

-   [#721](prettier/eslint-plugin-prettier#721) [`4f5513d`](prettier/eslint-plugin-prettier@4f5513d) Thanks [@JounQin](https://github.com/JounQin)! - fix: clarify correct `eslint-config-prettier` peer range


## [v5.2.4](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#524)

##### Patch Changes

-   [#715](prettier/eslint-plugin-prettier#715) [`b8cfe56`](prettier/eslint-plugin-prettier@b8cfe56) Thanks [@JounQin](https://github.com/JounQin)! - chore: hourcekeeping, bump all (dev) deps
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 10, 2025
| datasource | package                | from  | to    |
| ---------- | ---------------------- | ----- | ----- |
| npm        | eslint-plugin-prettier | 5.2.3 | 5.4.0 |


## [v5.4.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#540)

##### Minor Changes

-   [#736](prettier/eslint-plugin-prettier#736) [`59a0cae`](prettier/eslint-plugin-prettier@59a0cae) Thanks [@yashtech00](https://github.com/yashtech00)! - refactor: migrate `worker.js` to `worker.mjs`


## [v5.3.1](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#531)

##### Patch Changes

-   [#734](prettier/eslint-plugin-prettier#734) [`dcf2c80`](prettier/eslint-plugin-prettier@dcf2c80) Thanks [@JounQin](https://github.com/JounQin)! - ci: enable `NPM_CONFIG_PROVENANCE` env


## [v5.3.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#530)

##### Minor Changes

-   [#674](prettier/eslint-plugin-prettier#674) [`6fe0c90`](prettier/eslint-plugin-prettier@6fe0c90) Thanks [@irsooti](https://github.com/irsooti)! - feat(types): prefer `Config` over `FlatConfig` when they're equal


## [v5.2.6](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#526)

##### Patch Changes

-   [#723](prettier/eslint-plugin-prettier#723) [`1451176`](prettier/eslint-plugin-prettier@1451176) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): bump `synckit` to `v0.11.0`


## [v5.2.5](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#525)

##### Patch Changes

-   [#721](prettier/eslint-plugin-prettier#721) [`4f5513d`](prettier/eslint-plugin-prettier@4f5513d) Thanks [@JounQin](https://github.com/JounQin)! - fix: clarify correct `eslint-config-prettier` peer range


## [v5.2.4](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#524)

##### Patch Changes

-   [#715](prettier/eslint-plugin-prettier#715) [`b8cfe56`](prettier/eslint-plugin-prettier@b8cfe56) Thanks [@JounQin](https://github.com/JounQin)! - chore: hourcekeeping, bump all (dev) deps
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request May 11, 2025
| datasource | package                | from  | to    |
| ---------- | ---------------------- | ----- | ----- |
| npm        | eslint-plugin-prettier | 5.2.3 | 5.4.0 |


## [v5.4.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#540)

##### Minor Changes

-   [#736](prettier/eslint-plugin-prettier#736) [`59a0cae`](prettier/eslint-plugin-prettier@59a0cae) Thanks [@yashtech00](https://github.com/yashtech00)! - refactor: migrate `worker.js` to `worker.mjs`


## [v5.3.1](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#531)

##### Patch Changes

-   [#734](prettier/eslint-plugin-prettier#734) [`dcf2c80`](prettier/eslint-plugin-prettier@dcf2c80) Thanks [@JounQin](https://github.com/JounQin)! - ci: enable `NPM_CONFIG_PROVENANCE` env


## [v5.3.0](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#530)

##### Minor Changes

-   [#674](prettier/eslint-plugin-prettier#674) [`6fe0c90`](prettier/eslint-plugin-prettier@6fe0c90) Thanks [@irsooti](https://github.com/irsooti)! - feat(types): prefer `Config` over `FlatConfig` when they're equal


## [v5.2.6](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#526)

##### Patch Changes

-   [#723](prettier/eslint-plugin-prettier#723) [`1451176`](prettier/eslint-plugin-prettier@1451176) Thanks [@renovate](https://github.com/apps/renovate)! - fix(deps): bump `synckit` to `v0.11.0`


## [v5.2.5](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#525)

##### Patch Changes

-   [#721](prettier/eslint-plugin-prettier#721) [`4f5513d`](prettier/eslint-plugin-prettier@4f5513d) Thanks [@JounQin](https://github.com/JounQin)! - fix: clarify correct `eslint-config-prettier` peer range


## [v5.2.4](https://github.com/prettier/eslint-plugin-prettier/blob/HEAD/CHANGELOG.md#524)

##### Patch Changes

-   [#715](prettier/eslint-plugin-prettier#715) [`b8cfe56`](prettier/eslint-plugin-prettier@b8cfe56) Thanks [@JounQin](https://github.com/JounQin)! - chore: hourcekeeping, bump all (dev) deps
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.

3 participants