Skip to content

Commit

Permalink
Make sure output have the last newline
Browse files Browse the repository at this point in the history
  • Loading branch information
youxkei committed Mar 5, 2021
1 parent e35f609 commit 2b05a6e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/trailing_separator_remover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ use std::fmt::Write;
use crate::node::{kind_id, KindId, Node, Tree};

pub fn remove_trailing_separators(tree: Tree, source_code: &str) -> String {
node_to_removed_code(tree.root_node(), source_code)
let mut result = node_to_removed_code(tree.root_node(), source_code);

if result.chars().last().unwrap() != '\n' {
write!(&mut result, "\n").unwrap();
}

result
}

fn node_to_removed_code(node: Node<'_>, source_code: &str) -> String {
Expand Down Expand Up @@ -349,8 +355,7 @@ mod remove_trailing_separators_test {
{#{foo := bar,}, #record{foo = bar,}, [foo,], <<"foo",>>,} = ok,
error,;.
"#},
error,;."#},
indoc! {r#"
-export([foo/1, bar/2]).
Expand Down

0 comments on commit 2b05a6e

Please sign in to comment.