Add a tidy check for leading trailing newlines
This commit is contained in:
parent
c21fbfe7e3
commit
8423e00714
@ -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| {
|
||||
@ -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 => {}
|
||||
|
Loading…
Reference in New Issue
Block a user