Skip to content

Commit eb56a5e

Browse files
authored
fix: separate the /flat entry for compatibility (#309)
close #308
1 parent 2c6f80e commit eb56a5e

File tree

7 files changed

+39
-12
lines changed

7 files changed

+39
-12
lines changed

.changeset/angry-kangaroos-sleep.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
"eslint-config-prettier": patch
3+
---
4+
5+
fix: separate the `/flat` entry for compatibility
6+
7+
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.
8+
9+
See also <https://github.com/prettier/eslint-config-prettier/issues/308>
10+
11+
```ts
12+
// before
13+
import eslintConfigPrettier from "eslint-config-prettier";
14+
15+
// after
16+
import eslintConfigPrettier from "eslint-config-prettier/flat";
17+
```

README.md

+7-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ Note that this config _only_ turns rules _off,_ so it only makes sense using it
4747
<!-- prettier-ignore -->
4848
```js
4949
import someConfig from "some-other-config-you-use";
50-
import eslintConfigPrettier from "eslint-config-prettier";
50+
// Note the `/flat` suffix here, the difference from default entry is that
51+
// `/flat` added `name` property to the exported object to improve
52+
// [config-inspector](https://eslint.org/blog/2024/04/eslint-config-inspector/) experience.
53+
import eslintConfigPrettier from "eslint-config-prettier/flat";
5154

5255
export default [
5356
someConfig,
@@ -81,7 +84,7 @@ With flat config, _you_ get to decide the plugin name! For example:
8184

8285
```js
8386
import typescriptEslint from "@typescript-eslint/eslint-plugin";
84-
import eslintConfigPrettier from "eslint-config-prettier";
87+
import eslintConfigPrettier from "eslint-config-prettier/flat";
8588

8689
export default [
8790
{
@@ -153,7 +156,7 @@ For eslintrc, while the `"prettier"` config can disable problematic rules in `"s
153156

154157
```js
155158
import someConfig from "some-other-config-you-use";
156-
import eslintConfigPrettier from "eslint-config-prettier";
159+
import eslintConfigPrettier from "eslint-config-prettier/flat";
157160

158161
export default [
159162
someConfig,
@@ -170,7 +173,7 @@ With the new ESLint “flat config” format, you can control what things overri
170173

171174
```js
172175
import someConfig from "some-other-config-you-use";
173-
import eslintConfigPrettier from "eslint-config-prettier";
176+
import eslintConfigPrettier from "eslint-config-prettier/flat";
174177

175178
export default [
176179
someConfig,

flat.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from "./index.js";
2+
3+
export const name: "config-prettier";

flat.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
3+
const { rules } = require("./index.js");
4+
5+
exports.name = "config-prettier";
6+
exports.rules = rules;

index.d.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
export const name: "config-prettier" | undefined;
2-
31
export const rules: Record<string, 0 | "off">;

index.js

-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
"use strict";
22

3-
const { version } = require("eslint/package.json");
4-
53
const includeDeprecated = !process.env.ESLINT_CONFIG_PRETTIER_NO_DEPRECATED;
64

75
const specialRule = 0;
86

9-
if (+version.split(".")[0] >= 9) {
10-
exports.name = "config-prettier";
11-
}
12-
137
exports.rules = {
148
// The following rules can be used in some cases. See the README for more
159
// information. These are marked with `0` instead of `"off"` so that a

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
"types": "./index.d.ts",
1818
"default": "./index.js"
1919
},
20+
"./flat": {
21+
"types": "./flat.d.ts",
22+
"default": "./flat.js"
23+
},
2024
"./prettier": {
2125
"types": "./prettier.d.ts",
2226
"default": "./prettier.js"
@@ -26,6 +30,8 @@
2630
"types": "index.d.ts",
2731
"files": [
2832
"bin",
33+
"flat.d.ts",
34+
"flat.js",
2935
"index.d.ts",
3036
"index.js",
3137
"prettier.d.ts",

0 commit comments

Comments
 (0)