Skip to content

Commit 58b0fe0

Browse files
committed
Add Tell Prettier To Not Format A Statement as a javascript til
1 parent cac816b commit 58b0fe0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010

1111
For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud).
1212

13-
_1101 TILs and counting..._
13+
_1102 TILs and counting..._
1414

1515
---
1616

@@ -407,6 +407,7 @@ _1101 TILs and counting..._
407407
- [Start Node Process In Specific Timezone](javascript/start-node-process-in-specific-timezone.md)
408408
- [String Interpolation With Template Literals](javascript/string-interpolation-with-template-literals.md)
409409
- [Support Nested Matching In Custom Jest Matchers](javascript/support-nested-matching-in-custom-jest-matchers.md)
410+
- [Tell Prettier To Not Format A Statement](javascript/tell-prettier-to-not-format-a-statement.md)
410411
- [Test Coverage Stats With Jest](javascript/test-coverage-stats-with-jest.md)
411412
- [Test Timing-Based Code With Jest Fake Timers](javascript/test-timing-based-code-with-jest-fake-timers.md)
412413
- [The Comma Operator](javascript/the-comma-operator.md)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)