Skip to content

Commit

Permalink
Rerun prettier on CONTRIBUTING.md
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Nov 11, 2019
1 parent 157166e commit 842d6f4
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ As the nodes are printing themselves and their children, they're additionally bu
```javascript
const { concat, group, indent, line } = require("prettier").doc.builders;

const printBinary = (path, opts, print) => (
const printBinary = (path, opts, print) =>
group(
concat([
concat([path.call(print, "body", 0), " "]),
path.getValue().body[1],
indent(concat([line, path.call(print, "body", 2)]))
])
)
);
);
```

Recall that the `binary` node looks like this:
Expand All @@ -99,10 +98,10 @@ This means that there is a node in the `0` position of the array that represents

So, the `printBinary` function is going to use the following `prettier` builders to build up the intermediate represention:

* `concat` - puts multiple nodes together and prints them without breaking them apart
* `group` - marks places where `prettier` could split text if the line gets too long; if the max line length is hit, `prettier` will break apart the outermost `group` node first
* `indent` - increases the current print indent for the contents of the node if the parent node is broken, e.g., if the `binary` node is too long to fit on one line, it will indent the right-hand operand
* `line` - puts a space if the group is not broken, otherwise puts a newline
- `concat` - puts multiple nodes together and prints them without breaking them apart
- `group` - marks places where `prettier` could split text if the line gets too long; if the max line length is hit, `prettier` will break apart the outermost `group` node first
- `indent` - increases the current print indent for the contents of the node if the parent node is broken, e.g., if the `binary` node is too long to fit on one line, it will indent the right-hand operand
- `line` - puts a space if the group is not broken, otherwise puts a newline

Once every node has been printed like the `binary` node above, the `print` node returns the intermediate representation to `prettier`.

Expand Down

0 comments on commit 842d6f4

Please sign in to comment.