docs: add detailed guide for shared configs (#16495)

This commit is contained in:
Lehoczky Zoltán authored and GitHub committed 2024-10-18 14:57:01 +08:00
1 parent 1e73934cae
commit e7ca215c3c
7 files changed
+443 -64

No files matched your search

@@ -136,37 +136,6 @@ overrides:
`files` is required for each override, and may be a string or array of strings. `excludeFiles` may be optionally provided to exclude files for a given rule, and may also be a string or array of strings.
## Sharing configurations
Sharing a Prettier configuration is simple: just publish a module that exports a configuration object, say `@company/prettier-config`, and reference it in your `package.json`:
```json
{
"name": "my-cool-library",
"version": "9000.0.1",
"prettier": "@company/prettier-config"
}
```
If you don’t want to use `package.json`, you can use any of the supported extensions to export a string, e.g. `.prettierrc.json`:
```json
"@company/prettier-config"
```
An example configuration repository is available [here](https://github.com/azz/prettier-config).
> Note: This method does **not** offer a way to _extend_ the configuration to overwrite some properties from the shared configuration. If you need to do that, import the file in a `.prettierrc.js` file and export the modifications, e.g:
>
> ```js
> import companyPrettierConfig from "@company/prettier-config";
>
> export default {
> ...companyPrettierConfig,
> semi: false,
> };
> ```
## Setting the [parser](options.md#parser) option
By default, Prettier automatically infers which parser to use based on the input file extension. Combined with `overrides` you can teach Prettier how to parse files it does not recognize.