You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: website/versioned_docs/version-stable/browser.md
+16-16
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,7 @@ Required options:
18
18
19
19
-**[`parser`](options.md#parser) (or [`filepath`](options.md#file-path))**: One of these options has to be specified for Prettier to know which parser to use.
20
20
21
-
-**`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource-options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in [https://unpkg.com/browse/prettier@3.4.2/plugins](https://unpkg.com/browse/prettier@3.4.2/plugins). Note that `estree` plugin should be loaded when printing JavaScript, TypeScript, Flow, or JSON.
21
+
-**`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource-options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in [https://unpkg.com/browse/prettier@3.5.0/plugins](https://unpkg.com/browse/prettier@3.5.0/plugins). Note that `estree` plugin should be loaded when printing JavaScript, TypeScript, Flow, or JSON.
22
22
23
23
You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option.
Copy file name to clipboardexpand all lines: website/versioned_docs/version-stable/configuration.md
+52-4
Original file line number
Diff line number
Diff line change
@@ -8,17 +8,37 @@ You can configure Prettier via (in order of precedence):
8
8
- A `"prettier"` key in your `package.json`, or [`package.yaml`](https://github.com/pnpm/pnpm/pull/1799) file.
9
9
- A `.prettierrc` file written in JSON or YAML.
10
10
- A `.prettierrc.json`, `.prettierrc.yml`, `.prettierrc.yaml`, or `.prettierrc.json5` file.
11
-
- A `.prettierrc.js`, or `prettier.config.js` file that exports an object using `export default` or `module.exports` (depends on the [`type`](https://nodejs.org/api/packages.html#type) value in your `package.json`).
12
-
- A `.prettierrc.mjs`, or `prettier.config.mjs` file that exports an object using `export default`.
13
-
- A `.prettierrc.cjs`, or `prettier.config.cjs` file that exports an object using `module.exports`.
11
+
- A `.prettierrc.js`, `prettier.config.js`, `.prettierrc.ts`, or `prettier.config.ts` file that exports an object using `export default` or `module.exports` (depends on the [`type`](https://nodejs.org/api/packages.html#type) value in your `package.json`).
12
+
- A `.prettierrc.mjs`, `prettier.config.mjs`, `.prettierrc.mts`, or `prettier.config.mts` file that exports an object using `export default`.
13
+
- A `.prettierrc.cjs`, `prettier.config.cjs`, `.prettierrc.cts`, or `prettier.config.cts` file that exports an object using `module.exports`.
14
14
- A `.prettierrc.toml` file.
15
15
16
+
:::info
17
+
18
+
TypeScript configuration files support requires [additional setup](#typescript-configuration-files)
19
+
20
+
:::
21
+
16
22
The configuration file will be resolved starting from the location of the file being formatted, and searching up the file tree until a config file is (or isn’t) found.
17
23
18
24
Prettier intentionally doesn’t support any kind of global configuration. This is to make sure that when a project is copied to another computer, Prettier’s behavior stays the same. Otherwise, Prettier wouldn’t be able to guarantee that everybody in a team gets the same consistent results.
19
25
20
26
The options you can use in the configuration file are the same as the [API options](options.md).
21
27
28
+
### TypeScript Configuration Files
29
+
30
+
TypeScript support for Node.js is currently experimental, Node.js>=22.6.0 is required and `--experimental-strip-types` is required to run Node.js.
// prettier.config.ts, .prettierrc.ts, prettier.config.mts, or .prettierrc.mts
97
+
98
+
import { typeConfig } from"prettier";
99
+
100
+
const config:Config= {
101
+
trailingComma: "none",
102
+
};
103
+
104
+
exportdefaultconfig;
105
+
```
106
+
107
+
TypeScript (CommonJS):
108
+
109
+
```ts
110
+
// prettier.config.ts, .prettierrc.ts, prettier.config.cts, or .prettierrc.cts
111
+
112
+
import { typeConfig } from"prettier";
113
+
114
+
const config:Config= {
115
+
trailingComma: "none",
116
+
};
117
+
118
+
module.exports=config;
119
+
```
120
+
73
121
YAML:
74
122
75
123
```yaml
@@ -171,7 +219,7 @@ You can also switch to the `flow` parser instead of the default `babel` for .js
171
219
172
220
## Configuration Schema
173
221
174
-
If you’d like a JSON schema to validate your configuration, one is available here: https://json.schemastore.org/prettierrc.
222
+
If you’d like a JSON schema to validate your configuration, one is available here: [https://json.schemastore.org/prettierrc](https://json.schemastore.org/prettierrc).
Copy file name to clipboardexpand all lines: website/versioned_docs/version-stable/ignore.md
+2
Original file line number
Diff line number
Diff line change
@@ -145,6 +145,8 @@ This type of ignore is only allowed to be used in top-level and aimed to disable
145
145
<!-- prettier-ignore-end -->
146
146
```
147
147
148
+
**Important:** You must have a blank line before `<!-- prettier-ignore-start -->` and `<!-- prettier-ignore-end -->` for Prettier to recognize the comments.
149
+
148
150
## YAML
149
151
150
152
To ignore a part of a YAML file, `# prettier-ignore` should be placed on the line immediately above the ignored node:
Configure how Prettier wraps object literals when they could fit on one line or span multiple lines.
175
+
176
+
By default, Prettier formats objects as multi-line if there is a newline prior to the first property. Authors can use this heuristic to contextually improve readability, though it has some downsides. See [Multi-line objects](rationale.md#multi-line-objects).
177
+
178
+
Valid options:
179
+
180
+
-`"preserve"` - Keep as multi-line, if there is a newline between the opening brace and first property.
181
+
-`"collapse"` - Fit to a single line when possible.
Put the `>` of a multi-line HTML (HTML, JSX, Vue, Angular) element at the end of the last line instead of being alone on the next line (does not apply to self closing elements).
Copy file name to clipboardexpand all lines: website/versioned_docs/version-stable/rationale.md
+5-3
Original file line number
Diff line number
Diff line change
@@ -29,9 +29,11 @@ It turns out that empty lines are very hard to automatically generate. The appro
29
29
30
30
### Multi-line objects
31
31
32
-
By default, Prettier’s printing algorithm prints expressions on a single line if they fit. Objects are used for a lot of different things in JavaScript, though, and sometimes it really helps readability if they stay multiline. See [object lists], [nested configs], [stylesheets] and [keyed methods], for example. We haven’t been able to find a good rule for all those cases, so Prettier instead keeps objects multiline if there’s a newline between the `{` and the first key in the original source code. A consequence of this is that long singleline objects are automatically expanded, but short multiline objects are never collapsed.
32
+
By default, Prettier’s printing algorithm prints expressions on a single line if they fit. Objects are used for a lot of different things in JavaScript, though, and sometimes it really helps readability if they stay multiline. See [object lists], [nested configs], [stylesheets] and [keyed methods], for example. We haven’t been able to find a good rule for all those cases, so by default Prettier keeps objects multi-line if there’s a newline between the `{` and the first key in the original source code. Consequently, long single-line objects are automatically expanded, but short multi-line objects are never collapsed.
33
33
34
-
**Tip:** If you have a multiline object that you’d like to join up into a single line:
34
+
You can disable this conditional behavior with the [`objectWrap`](options.md#object-wrap) option.
35
+
36
+
**Tip:** If you have a multi-line object that you’d like to join up into a single line:
0 commit comments