Skip to content

Commit

Permalink
fix: separate the /flat entry for compatibility (#309)
Browse files Browse the repository at this point in the history
close #308
  • Loading branch information
JounQin authored Mar 7, 2025
1 parent 2c6f80e commit eb56a5e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 12 deletions.
17 changes: 17 additions & 0 deletions .changeset/angry-kangaroos-sleep.md
Original file line number Diff line number Diff line change
@@ -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 <https://github.com/prettier/eslint-config-prettier/issues/308>

```ts
// before
import eslintConfigPrettier from "eslint-config-prettier";

// after
import eslintConfigPrettier from "eslint-config-prettier/flat";
```
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ Note that this config _only_ turns rules _off,_ so it only makes sense using it
<!-- prettier-ignore -->
```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,
Expand Down Expand Up @@ -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 [
{
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions flat.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./index.js";

export const name: "config-prettier";
6 changes: 6 additions & 0 deletions flat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";

const { rules } = require("./index.js");

exports.name = "config-prettier";
exports.rules = rules;
2 changes: 0 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
export const name: "config-prettier" | undefined;

export const rules: Record<string, 0 | "off">;
6 changes: 0 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -26,6 +30,8 @@
"types": "index.d.ts",
"files": [
"bin",
"flat.d.ts",
"flat.js",
"index.d.ts",
"index.js",
"prettier.d.ts",
Expand Down

0 comments on commit eb56a5e

Please sign in to comment.