diff --git a/.changeset/eleven-foxes-bet.md b/.changeset/eleven-foxes-bet.md new file mode 100644 index 00000000..b0c0cdb1 --- /dev/null +++ b/.changeset/eleven-foxes-bet.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-prettier": minor +--- + +Add support for the standard flat file format. diff --git a/README.md b/README.md index 6bc12623..f0353062 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/eslint-plugin-prettier.d.ts b/eslint-plugin-prettier.d.ts index eafdb4a1..72ba13c8 100644 --- a/eslint-plugin-prettier.d.ts +++ b/eslint-plugin-prettier.d.ts @@ -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 + >[]; + }; +}; export = eslintPluginPrettier; diff --git a/eslint-plugin-prettier.js b/eslint-plugin-prettier.js index 0ef19af9..8c56e0b8 100644 --- a/eslint-plugin-prettier.js +++ b/eslint-plugin-prettier.js @@ -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: {