Take into account a trailing newline in buffer

This commit is contained in:
Seiichi Uchida 2017-12-05 17:15:42 +09:00
parent 5632a7c075
commit 1d1305eef8

View File

@ -87,6 +87,10 @@ impl<'a> FmtVisitor<'a> {
}
fn push_vertical_spaces(&mut self, mut newline_count: usize) {
// The buffer already has a trailing newline.
if self.buffer.cur_offset() == 0 {
newline_count = newline_count.checked_sub(1).unwrap_or(0);
}
let newline_upper_bound = self.config.blank_lines_upper_bound() + 1;
let newline_lower_bound = self.config.blank_lines_lower_bound() + 1;
if newline_count > newline_upper_bound {