关闭所有不必要或可能与 Prettier 冲突的规则。
关闭所有不必要的或可能与 [Prettier] 冲突的规则。
这让你可以使用自己喜欢的共享配置,同时在使用 Prettier 时不会受到其风格选择的影响。
请注意,此配置_只_会关闭规则,因此只有与其他配置一起使用才有意义。
npm i -D eslint-config-prettier yarn add -D eslint-config-prettier pnpm add -D eslint-config-prettier bun add -D eslint-config-prettier"prettier" 添加到你的 .eslintrc.* 文件中的 "extends" 数组中。务必把它放在最后,这样它才有机会覆盖其他配置。 {
"extends": [
"some-other-config-you-use",
"prettier"
]
}
```
- eslint.config.js(flat config):导入 eslint-config-prettier,并将其放入配置数组中——放在你想覆盖的其他配置**之后**。
```js
import someConfig from "some-other-config-you-use";
// 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,
eslintConfigPrettier,
];
```
3. 最后,运行 [CLI 辅助工具](#cli-helper-tool) 来查找你配置中 `"rules"` 部分的问题。
> 使用了 [eslint-plugin-prettier]?请查看 [eslint-plugin-prettier 的推荐配置][eslint-plugin-prettier-recommended]。
### 插件
eslint-config-prettier 不仅会关闭_核心_规则,还会自动关闭来自这些插件的一些规则:
- [@babel/eslint-plugin]
- [@stylistic/eslint-plugin]
- [@TypeScript-eslint/eslint-plugin]
- [eslint-plugin-
[prettier]: https://github.com/prettier/prettier暂无开放 Issues,或尚未同步最近议题。