Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't add extra newline in last inline node #555

Merged
merged 1 commit into from
Aug 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,30 +326,27 @@ function fileShouldEndWithHardline(path) {
const node = path.getValue();
const isProgramNode = node.kind === "program";
const lastNode = node.children && getLast(node.children);

if (!isProgramNode) {
return false;
}
if (
lastNode &&
lastNode.kind === "inline" &&
lastNode.raw[lastNode.raw.length - 1] === "\n"
) {

if (lastNode && lastNode.kind === "inline") {
return false;
}

if (
lastNode &&
(lastNode.kind === "declare" || lastNode.kind === "namespace")
) {
const lastNestedNode =
lastNode.children.length > 0 && getLast(lastNode.children);
if (
lastNestedNode &&
lastNestedNode.kind === "inline" &&
lastNestedNode.raw[lastNestedNode.raw.length - 1] === "\n"
) {

if (lastNestedNode && lastNestedNode.kind === "inline") {
return false;
}
}

return true;
}

Expand Down
1 change: 0 additions & 1 deletion tests/inline/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ text
}
} ?>
text

`;

exports[`mixed-6.php 1`] = `
Expand Down
3 changes: 1 addition & 2 deletions tests/markdown/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ if (true) {
}
echo 'bar';
?>
test
\`\`\`
test\`\`\`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug in prettier prettier/prettier#5037


`;