Skip to content

Commit

Permalink
All JSXElement siblings on separate lines
Browse files Browse the repository at this point in the history
  • Loading branch information
rattrayalex committed Jan 12, 2017
1 parent 5e21062 commit aa45c6c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/printer.js
Expand Up @@ -2010,6 +2010,11 @@ function printJSXElement(path, options, print) {
children.push(hardline);
}
} else {
// ensure sibling `JSXElement`s are on separate lines (strings have no "type")
const prev = util.getLast(children);
if (prev && prev.type !== "line") {
children.push(softline);
}
children.push(print(childPath));
}
},
Expand Down
22 changes: 20 additions & 2 deletions tests/prettier/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -146,12 +146,18 @@ const render5 = ({ styles }) => <div>Keep it on one line.</div>;
const render6 = ({ styles }) => (
<div attr1=\"aaaaaaaaaaaaaaaaa\" attr2=\"bbbbbbbbbbb\" attr3=\"cccccccccccc\">
<div attr1=\"aaaaaaaaaaaaaaaaa\" attr2=\"bbbbbbbbbbb\" attr3=\"cccccccccccc\" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div>
<div attr1=\"aaaaaaaaaaaaaaaaa\" attr2=\"bbbbbbbbbbb\" attr3=\"cccccccccccc\" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div>
<div attr1=\"aaaaaaaaaaaaaaaaa\" attr2=\"bbbbbbbbbbb\" attr3=\"cccccccccccc\" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div><strong>goodbye</strong>
<div attr1=\"aaaaaaaaaaaaaaaaa\" attr2=\"bbbbbbbbbbb\" attr3=\"cccccccccccc\" attr4>
<div attr1=\"aaaaaaaaaaaaaaaaa\" attr2=\"bbbbbbbbbbb\" attr3=\"cccccccccccc\" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div> <strong>hello</strong></div>
</div>
)
const render7 = () =>
<div>
<span /><span>Break each elem onto its own line.</span> <span />
<div /> <div />
</div>
const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams(cccccccccccc, dddddddddddddddddddddd)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
const render1 = ({ styles }) => (
Expand Down Expand Up @@ -196,6 +202,7 @@ const render6 = ({ styles }) => (
>
ddd d dd d d dddd dddd <strong>hello</strong>
</div>
<strong>goodbye</strong>
<div
attr1=\"aaaaaaaaaaaaaaaaa\"
attr2=\"bbbbbbbbbbb\"
Expand All @@ -209,11 +216,22 @@ const render6 = ({ styles }) => (
attr4
>
ddd d dd d d dddd dddd <strong>hello</strong>
</div><strong>hello</strong>
</div>
<strong>hello</strong>
</div>
</div>
);
const render7 = () => (
<div>
<span />
<span>Break each elem onto its own line.</span>
<span />
<div />
<div />
</div>
);
const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) =>
this
.someLongCallWithParams(aaaaaa, bbbbbbb)
Expand Down
8 changes: 7 additions & 1 deletion tests/prettier/jsx-stateless-arrow-fn.js
Expand Up @@ -17,10 +17,16 @@ const render5 = ({ styles }) => <div>Keep it on one line.</div>;
const render6 = ({ styles }) => (
<div attr1="aaaaaaaaaaaaaaaaa" attr2="bbbbbbbbbbb" attr3="cccccccccccc">
<div attr1="aaaaaaaaaaaaaaaaa" attr2="bbbbbbbbbbb" attr3="cccccccccccc" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div>
<div attr1="aaaaaaaaaaaaaaaaa" attr2="bbbbbbbbbbb" attr3="cccccccccccc" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div>
<div attr1="aaaaaaaaaaaaaaaaa" attr2="bbbbbbbbbbb" attr3="cccccccccccc" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div><strong>goodbye</strong>
<div attr1="aaaaaaaaaaaaaaaaa" attr2="bbbbbbbbbbb" attr3="cccccccccccc" attr4>
<div attr1="aaaaaaaaaaaaaaaaa" attr2="bbbbbbbbbbb" attr3="cccccccccccc" attr4>ddd d dd d d dddd dddd <strong>hello</strong></div> <strong>hello</strong></div>
</div>
)

const render7 = () =>
<div>
<span /><span>Break each elem onto its own line.</span> <span />
<div /> <div />
</div>

const notJSX = (aaaaaaaaaaaaaaaaa, bbbbbbbbbbb) => this.someLongCallWithParams(aaaaaa, bbbbbbb).anotherLongCallWithParams(cccccccccccc, dddddddddddddddddddddd)

0 comments on commit aa45c6c

Please sign in to comment.