93 lines
1.6 KiB
Markdown
93 lines
1.6 KiB
Markdown
---
|
|
id: ignore
|
|
title: Ignoring Code
|
|
---
|
|
|
|
Prettier offers an escape hatch to ignore a block of code or prevent entire files from being formatted.
|
|
|
|
## Ignoring Files
|
|
|
|
To exclude files from formatting, add entries to a `.prettierignore` file in the project root or set the [`--ignore-path` CLI option](cli.md#ignore-path).
|
|
|
|
## JavaScript
|
|
|
|
A JavaScript comment of `// prettier-ignore` will exclude the next node in the abstract syntax tree from formatting.
|
|
|
|
For example:
|
|
|
|
<!-- prettier-ignore -->
|
|
```js
|
|
matrix(
|
|
1, 0, 0,
|
|
0, 1, 0,
|
|
0, 0, 1
|
|
)
|
|
|
|
// prettier-ignore
|
|
matrix(
|
|
1, 0, 0,
|
|
0, 1, 0,
|
|
0, 0, 1
|
|
)
|
|
```
|
|
|
|
will be transformed to:
|
|
|
|
```js
|
|
matrix(1, 0, 0, 0, 1, 0, 0, 0, 1);
|
|
|
|
// prettier-ignore
|
|
matrix(
|
|
1, 0, 0,
|
|
0, 1, 0,
|
|
0, 0, 1
|
|
)
|
|
```
|
|
|
|
## JSX
|
|
|
|
```jsx
|
|
<div>
|
|
{/* prettier-ignore */}
|
|
<span ugly format='' />
|
|
</div>
|
|
```
|
|
|
|
## CSS
|
|
|
|
```css
|
|
/* prettier-ignore */
|
|
.my ugly rule
|
|
{
|
|
|
|
}
|
|
```
|
|
|
|
## Markdown
|
|
|
|
```markdown
|
|
<!-- prettier-ignore -->
|
|
Do not format this
|
|
```
|
|
|
|
### Range Ignore
|
|
|
|
_available in v1.12.0+_
|
|
|
|
This type of ignore is only allowed to be used in top-level and aimed to disable formatting for auto-generated content, e.g. [`all-contributors`](https://github.com/kentcdodds/all-contributors), [`markdown-toc`](https://github.com/jonschlinkert/markdown-toc), etc.
|
|
|
|
<!-- TODO: remove this ignore when upgraded to v1.12 -->
|
|
|
|
<!-- prettier-ignore -->
|
|
```markdown
|
|
<!-- prettier-ignore-start -->
|
|
<!-- SOMETHING AUTO-GENERATED BY TOOLS - START -->
|
|
|
|
| MY | AWESOME | AUTO-GENERATED | TABLE |
|
|
|-|-|-|-|
|
|
| a | b | c | d |
|
|
|
|
<!-- SOMETHING AUTO-GENERATED BY TOOLS - END -->
|
|
<!-- prettier-ignore-end -->
|
|
```
|