diff --git a/.changeset/angry-kangaroos-sleep.md b/.changeset/angry-kangaroos-sleep.md new file mode 100644 index 0000000..4fef474 --- /dev/null +++ b/.changeset/angry-kangaroos-sleep.md @@ -0,0 +1,17 @@ +--- +"eslint-config-prettier": patch +--- + +fix: separate the `/flat` entry for compatibility + +For flat config users, the previous `"eslint-config-prettier"` entry still works, but `"eslint-config-prettier/flat"` adds a new `name` property for [config-inspector](https://eslint.org/blog/2024/04/eslint-config-inspector/), we just can't add it for the default entry for compatibility. + +See also + +```ts +// before +import eslintConfigPrettier from "eslint-config-prettier"; + +// after +import eslintConfigPrettier from "eslint-config-prettier/flat"; +``` diff --git a/README.md b/README.md index 4dbad9d..2bdb30c 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,10 @@ Note that this config _only_ turns rules _off,_ so it only makes sense using it ```js import someConfig from "some-other-config-you-use"; - import eslintConfigPrettier from "eslint-config-prettier"; + // Note the `/flat` suffix here, the difference from default entry is that + // `/flat` added `name` property to the exported object to improve + // [config-inspector](https://eslint.org/blog/2024/04/eslint-config-inspector/) experience. + import eslintConfigPrettier from "eslint-config-prettier/flat"; export default [ someConfig, @@ -81,7 +84,7 @@ With flat config, _you_ get to decide the plugin name! For example: ```js import typescriptEslint from "@typescript-eslint/eslint-plugin"; -import eslintConfigPrettier from "eslint-config-prettier"; +import eslintConfigPrettier from "eslint-config-prettier/flat"; export default [ { @@ -153,7 +156,7 @@ For eslintrc, while the `"prettier"` config can disable problematic rules in `"s ```js import someConfig from "some-other-config-you-use"; -import eslintConfigPrettier from "eslint-config-prettier"; +import eslintConfigPrettier from "eslint-config-prettier/flat"; export default [ someConfig, @@ -170,7 +173,7 @@ With the new ESLint “flat config” format, you can control what things overri ```js import someConfig from "some-other-config-you-use"; -import eslintConfigPrettier from "eslint-config-prettier"; +import eslintConfigPrettier from "eslint-config-prettier/flat"; export default [ someConfig, diff --git a/flat.d.ts b/flat.d.ts new file mode 100644 index 0000000..82c3862 --- /dev/null +++ b/flat.d.ts @@ -0,0 +1,3 @@ +export * from "./index.js"; + +export const name: "config-prettier"; diff --git a/flat.js b/flat.js new file mode 100644 index 0000000..adf9dee --- /dev/null +++ b/flat.js @@ -0,0 +1,6 @@ +"use strict"; + +const { rules } = require("./index.js"); + +exports.name = "config-prettier"; +exports.rules = rules; diff --git a/index.d.ts b/index.d.ts index c3920b9..bed98ae 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1 @@ -export const name: "config-prettier" | undefined; - export const rules: Record; diff --git a/index.js b/index.js index 170b470..dc39bee 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,9 @@ "use strict"; -const { version } = require("eslint/package.json"); - const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED; const specialRule = 0; -if (+version.split(".")[0] >= 9) { - exports.name = "config-prettier"; -} - exports.rules = { // The following rules can be used in some cases. See the README for more // information. These are marked with `0` instead of `"off"` so that a diff --git a/package.json b/package.json index 0e6a9f6..e695539 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,10 @@ "types": "./index.d.ts", "default": "./index.js" }, + "./flat": { + "types": "./flat.d.ts", + "default": "./flat.js" + }, "./prettier": { "types": "./prettier.d.ts", "default": "./prettier.js" @@ -26,6 +30,8 @@ "types": "index.d.ts", "files": [ "bin", + "flat.d.ts", + "flat.js", "index.d.ts", "index.js", "prettier.d.ts",