This is a placeholder value where the cursor is in the original input in order to find where it would be printed.
Line break that is always behaves as if it did not fit, regardless if the group fits on one line or not.
Line break. If a group fits on one line it prints a single space. If group does not fit it prints line break and an indentetation.
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.
concat(["{", lineSuffix(" // comment"), lineSuffixBoundary, "}", hardline])
will output
{ // comment
}
and not
{} // comment
Line break that is always behaves as if it did not fit. Unlike other lines though it does not print indetantion after line break. Prettier uses this for template literals.
Line break. If a group fits on one line it prints nothing. If group does not
fit it behaves same as line
.
This is similar to indent
but it increases the level of indentation
for the given content
by a given n
fixed number. When using tabs, it's
going to print spaces. You should prefer using indent
whenever possible.
align(tabWidth, concat(["hello", line, "world"]))
This should be used as last resort as it triggers an exponential complexity when nested. This will try to print the first option, if it fits use it, otherwise try next one and so on.
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.
fill(["I", line, "love", line, "prettier"])
Mark a group of fragments which the printer should try to print on one line. This tell the printer formatter when to break. Groups are usually nested, and the printer will try to fit everything on one line, but if it doesn't fit it will break the outermost group first and try again. It will continue breaking groups until everything fits (or there are no more groups to break).
A document can force parent groups to break by including breakParent
.
A "hard" and "literal" line
automatically include this so they always
break parent groups. Breaks are propagated to all parent groups, so if a
deeply nested expression has a hard break, everything with break. This only
matters for "hard" breaks, i.e. newlines that are printed no matter what
and can be statically analyzed.
For example, an array will try to fit on one line:
[1, "foo", { bar: 2 }]
However, if any of the items inside the array have a hard break, the array will always break as well:
[
1,
function() {
return 2
},
3
]
In prettier functions always break after the opening curly brace no matter
what, so the array breaks as well for consistent formatting. See the prettier
implementation of ArrayExpression
for an example.
group(
concat([
"[",
indent(
concat([
line,
join(
concat([",", line]),
path.map(print, "elements")
)
])
),
line,
"]"
])
)
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 or lineSuffixBoundary
.
concat(["a", lineSuffix(" // comment"), ";", hardline])
will output
a; // comment
Generated using TypeDoc
Include this anywhere to force all parent groups to break. See
group
for more info. Example:group( concat([ " ", expr, " ", breakParent ]) )