Repository navigation
Description
prettier wraps lines and indents by the regular indentation level, i.e. +2 whitespace by default:
if (this.line.is.very.long()
&& moreCodeHere) {
bodyOfBlock();
}
const similarilyAssumingLongVariableNames =
someValue;Many style guides (see citations below) request a 2 * indent for wrapped lines (also known as continuation indent), to make them stand out more from the body of the block:
if (this.line.is.very.long()
&& moreCodeHere) { // note: +4 indent here, not +2
bodyOfBlock();
}
const similarilyAssumingLongVariableNames =
someValue;The reasoning is that it's otherwise easy to mix up statements of the body with expressions from the wrapped line, and indent from control structures/blocks (such as if statements) is more easily distinguished from wrapped lines.
This isn't universal, e.g. AirBnB's style guide is not explicit on the issue, but examples use a +2 continuation indent.
Would this be a valid option for prettier?
[0] https://contribute.jquery.org/style-guide/js/#multi-line-statements
[1] https://github.com/twitter/commons/blob/master/src/java/com/twitter/common/styleguide.md#indent-style
[2] https://google.github.io/styleguide/javaguide.html#s4.5.2-line-wrapping-indent
[3] https://google.github.io/styleguide/jsguide.html#formatting-indent
[4] https://www.oracle.com/technetwork/java/codeconventions-150003.pdf
[5] counter example: https://github.com/airbnb/javascript
Activity
lydell commentedon Feb 14, 2019
It's already clearly separated:
Prettier 1.16.4
Playground link
Input:
Output:
voithos commentedon Feb 14, 2019
Prettier seems to do something analogous to this with template languages, as well (at least, I've seen this on Angular template formatting). If the opening tag is wrapped (e.g. because it has many attributes), the indent is +2 by default.
This seems to create a bit of a visual imbalance (perhaps more so than the JS examples), since the opening tag name is attached to the first
<, instead of going on the next line. Compare to the +4 continuation indent example, which seems to more clearly differentiate between inner HTML vs continuation lines:no-response commentedon Feb 28, 2019
This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.
vincent-olivert-riera commentedon Mar 10, 2019
@lydell can this issue be reopened? I'm interested on that feature (double-indent for wrapped lines).
lydell commentedon Mar 10, 2019
@vincent-olivert-riera Feel free to open a new issue! It is not clear what this one is about anymore.
mprobst commentedon Mar 10, 2019