Skip to content

Commit

Permalink
Put parenthesis after return when jsx is prettier-ignored (prettier#2665
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vjeux authored Aug 25, 2017
1 parent 0ee74a8 commit 0d38136
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,27 @@ function getPrintFunction(options) {

function hasIgnoreComment(path) {
const node = path.getValue();
return hasNodeIgnoreComment(node) || hasJsxIgnoreComment(path);
}

function hasNodeIgnoreComment(node) {
return (
node &&
((node.comments &&
node.comments.length > 0 &&
node.comments.some(
comment => comment.value.trim() === "prettier-ignore"
)) ||
hasJsxIgnoreComment(path))
node.comments &&
node.comments.length > 0 &&
node.comments.some(comment => comment.value.trim() === "prettier-ignore")
);
}

function hasJsxIgnoreComment(path) {
const node = path.getValue();
const parent = path.getParentNode();
if (!parent || node.type !== "JSXElement" || parent.type !== "JSXElement") {
if (
!parent ||
!node ||
node.type !== "JSXElement" ||
parent.type !== "JSXElement"
) {
return false;
}

Expand Down Expand Up @@ -4385,7 +4391,7 @@ function hasTrailingComment(node) {

function hasLeadingOwnLineComment(text, node) {
if (node.type === "JSXElement") {
return false;
return hasNodeIgnoreComment(node);
}

const res =
Expand Down
16 changes: 16 additions & 0 deletions tests/jsx_ignore/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ push(
<td> :)
</td>,
);
function f() {
return (
// prettier-ignore
/* $FlowFixMe(>=0.53.0) */
<JSX />
);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// this should remain as-is
<div>
Expand Down Expand Up @@ -93,4 +101,12 @@ push(
</td>
);
function f() {
return (
// prettier-ignore
/* $FlowFixMe(>=0.53.0) */
<JSX />
);
}
`;
8 changes: 8 additions & 0 deletions tests/jsx_ignore/jsx_ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,11 @@ push(
<td> :)
</td>,
);

function f() {
return (
// prettier-ignore
/* $FlowFixMe(>=0.53.0) */
<JSX />
);
}

0 comments on commit 0d38136

Please sign in to comment.