Trim end and add empty line for POSIX

This commit is contained in:
Philippe Vinchon 2022-03-05 22:31:57 +00:00
parent cad02d878c
commit 813845e7d1
2 changed files with 9 additions and 0 deletions

View file

@ -180,6 +180,9 @@ fn fmt_all<'a>(arena: &'a Bump, buf: &mut Buf<'a>, ast: &'a Ast) {
for def in &ast.defs {
fmt_def(buf, arena.alloc(def.value), 0);
}
buf.trim_end();
buf.newline();
}
/// RemoveSpaces normalizes the ast to something that we _expect_ to be invariant under formatting.

View file

@ -90,4 +90,10 @@ impl<'a> Buf<'a> {
self.spaces_to_flush = 0;
}
}
pub fn trim_end(&mut self) {
while self.text.ends_with(char::is_whitespace) {
self.text.truncate(self.text.len() - 1);
}
}
}