Skip to content

Commit

Permalink
Add a tidy check for leading trailing newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Apr 22, 2019
1 parent 4530c52 commit 10a1f41
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn check(path: &Path, bad: &mut bool) {
let skip_length = contents.contains("ignore-tidy-linelength");
let skip_end_whitespace = contents.contains("ignore-tidy-end-whitespace");
let skip_copyright = contents.contains("ignore-tidy-copyright");
let mut leading_new_lines = false;
let mut trailing_new_lines = 0;
for (i, line) in contents.split('\n').enumerate() {
let mut err = |msg: &str| {
Expand Down Expand Up @@ -152,11 +153,17 @@ pub fn check(path: &Path, bad: &mut bool) {
err(LLVM_UNREACHABLE_INFO);
}
if line.is_empty() {
if i == 0 {
leading_new_lines = true;
}
trailing_new_lines += 1;
} else {
trailing_new_lines = 0;
}
}
if leading_new_lines {
tidy_error!(bad, "{}: leading newline", file.display());
}
match trailing_new_lines {
0 => tidy_error!(bad, "{}: missing trailing newline", file.display()),
1 | 2 => {}
Expand Down

0 comments on commit 10a1f41

Please sign in to comment.