|
| 1 | +# Tell Prettier To Not Format A Statement |
| 2 | + |
| 3 | +[Prettier](https://prettier.io/) is a boon to productivity because individuals |
| 4 | +and teams don't have to make any decisions about the fine details of how their |
| 5 | +code is formatted. Generally, let `prettier` do its thing. |
| 6 | + |
| 7 | +There are some situations where you want to preserve your own formatting, |
| 8 | +especially if it improves readability. |
| 9 | + |
| 10 | +Here is some `prettier` formatted code: |
| 11 | + |
| 12 | +```javascript |
| 13 | +const relativeCoords = { |
| 14 | + A: [xPos - 1, yPos - 1], |
| 15 | + B: [xPos, yPos - 1], |
| 16 | + C: [xPos + 1, yPos - 1], |
| 17 | + D: [xPos - 1, yPos], |
| 18 | + E: [xPos + 1, yPos], |
| 19 | + F: [xPos - 1, yPos + 1], |
| 20 | + G: [xPos, yPos + 1], |
| 21 | + H: [xPos + 1, yPos + 1], |
| 22 | +}; |
| 23 | +``` |
| 24 | + |
| 25 | +Originally, I included some whitespace to keep things visually aligned. If I |
| 26 | +include a `prettier-ignore` comment, the statement immediately following it |
| 27 | +will not be touched by prettier. |
| 28 | + |
| 29 | +```javascript |
| 30 | +// prettier-ignore |
| 31 | +const relativeCoords = { |
| 32 | + A: [xPos - 1, yPos - 1], |
| 33 | + B: [xPos , yPos - 1], |
| 34 | + C: [xPos + 1, yPos - 1], |
| 35 | + D: [xPos - 1, yPos ], |
| 36 | + E: [xPos + 1, yPos ], |
| 37 | + F: [xPos - 1, yPos + 1], |
| 38 | + G: [xPos , yPos + 1], |
| 39 | + H: [xPos + 1, yPos + 1], |
| 40 | +}; |
| 41 | +``` |
| 42 | + |
| 43 | +[source](https://prettier.io/docs/en/ignore.html#javascript) |
0 commit comments