2017-11-07 14:39:07 +11:00
---
id : ignore
title : Ignoring Code
---
2017-12-12 01:23:06 +01:00
Prettier offers an escape hatch to ignore a block of code or prevent entire files from being formatted.
## Ignoring Files
2020-04-01 02:25:17 +02:00
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 ). `.prettierignore` uses [gitignore syntax ](https://git-scm.com/docs/gitignore#_pattern_format ).
2017-11-07 14:39:07 +11:00
## JavaScript
A JavaScript comment of `// prettier-ignore` will exclude the next node in the abstract syntax tree from formatting.
For example:
2017-11-22 19:27:40 +08:00
<!-- prettier-ignore -->
2017-11-07 14:39:07 +11:00
```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 >
2017-11-22 19:27:40 +08:00
{ /* prettier-ignore */ }
< span ugly format = '' />
2017-12-05 21:14:03 +11:00
</ div >
2017-11-07 14:39:07 +11:00
```
2018-11-07 09:09:04 +08:00
## HTML
```html
<!-- prettier-ignore -->
< div class = "x" > hello world</ div >
<!-- prettier-ignore-attribute -->
< div
( mousedown )=" onStart ( ) "
( mouseup )=" onEnd ( ) "
></ div >
<!-- prettier-ignore-attribute (mouseup) -->
< div
( mousedown )=" onStart ()"
( mouseup )=" onEnd ( ) "
></ div >
```
2017-11-07 14:39:07 +11:00
## CSS
```css
/* prettier-ignore */
. my ugly rule
{
}
```
## Markdown
```markdown
<!-- prettier-ignore -->
Do not format this
```
2018-03-27 00:03:28 +08:00
### 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.
```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 -->
```
2018-07-04 18:02:07 +02:00
2020-05-12 16:00:28 +03:00
## YAML
To ignore a part of a YAML file, `# prettier-ignore` should be placed on the line immediately above the ignored node:
```yaml
# prettier-ignore
key : value
hello : world
```
2018-07-04 18:02:07 +02:00
## GraphQL
```graphql
{
# prettier-ignore
addReaction ( input :{ superLongInputFieldName : "MDU6SXNzdWUyMzEzOTE1NTE=" , content : HOORAY }) {
reaction { content }
}
}
```
2020-01-20 05:19:09 -05:00
## Handlebars
<!-- prettier-ignore -->
```hbs
{{! prettier-ignore }}
<div>
"hello! my parent was ignored"
{{ #my-crazy-component "shall" be = "preserved" }}
<This
is = "also preserved as is"
/>
{{ /my-crazy-component }}
</div>
```