Update commands.md

master
Christopher Chedeau 2017-06-07 11:42:31 -07:00 committed by GitHub
parent 9d4fabd691
commit e1ebbff001
1 changed files with 68 additions and 0 deletions

View File

@ -54,6 +54,31 @@ Functions always break after the opening curly brace no matter what,
so the array breaks as well for consistent formatting. See the
implementation of `ArrayExpression` for an example.
### conditionalGroup
This should be used as **last resort** as it triggers an exponential complexity when nested. This will try to print the first argument, if it fit use it, otherwise go to the next one and so on.
```js
conditionalGroup([a, b, c])
```
### fill
This is an alternative type of group which behave like text layout: it's going to add a break whenever the next element doesn't fit in the line anymore. The difference with a typical group is that it's not going to break all the separators, just the ones that are at the end of lines.
```js
fill(["I", line, "love", line, "prettier"])
```
### ifBreak
Prints something if the current group breaks and something else if it doesn't.
```js
ifBreak(";", " ")
```
### breakParent
Include this anywhere to force all parent groups to break. See `group`
@ -95,10 +120,53 @@ matter if the expression fits on one line or not.
Specify a line break that is **always** included in the output, and
don't indent the next line. This is used for template literals.
### lineSuffix
This is used to implement trailing comments. In practice, it is not practical to find where the line ends and you don't want to accidentally print some code at the end of the comment. `lineSuffix` will buffer the output and flush it before any new line.
```js
concat(["a", lineSuffix(" // comment"), ";", hardline])
```
will output
```js
a; // comment
```
### lineSuffixBoundary
In cases where you embed code inside of templates, comments shouldn't be able to leave the code part. lineSuffixBoundary is an explicit marker you can use to flush code in addition to newlines.
```js
concat(["{", lineSuffix(" // comment"), lineSuffixBoundary, "}", hardline])
```
will output
```js
{ // comment
}
```
and **not**
```js
{} // comment
```
### indent
Increase the level of indentation.
### align
This is similar to indent but it increases the level of indentation by a fixed number. When using tabs, it's going to print spaces. You should prefer using `indent` whenever possible.
### cursor
This is a placeholder value where the cursor is in the original input in order to find where it would be printed.
## Example
For an example, here's the implementation of the `ArrayExpression` node type: