@@ -130,6 +130,7 @@ pub fn check(path: &Path, bad: &mut bool) {
130130 let skip_tab = contents. contains ( "ignore-tidy-tab" ) ;
131131 let skip_length = contents. contains ( "ignore-tidy-linelength" ) ;
132132 let skip_end_whitespace = contents. contains ( "ignore-tidy-end-whitespace" ) ;
133+ let mut trailing_new_lines = 0 ;
133134 for ( i, line) in contents. split ( "\n " ) . enumerate ( ) {
134135 let mut err = |msg : & str | {
135136 tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , i + 1 , msg) ;
@@ -161,10 +162,20 @@ pub fn check(path: &Path, bad: &mut bool) {
161162 if filename. ends_with ( ".cpp" ) && line. contains ( "llvm_unreachable" ) {
162163 err ( LLVM_UNREACHABLE_INFO ) ;
163164 }
165+ if line. is_empty ( ) {
166+ trailing_new_lines += 1 ;
167+ } else {
168+ trailing_new_lines = 0 ;
169+ }
164170 }
165171 if !licenseck ( file, & contents) {
166172 tidy_error ! ( bad, "{}: incorrect license" , file. display( ) ) ;
167173 }
174+ match trailing_new_lines {
175+ 0 => tidy_error ! ( bad, "{}: missing trailing newline" , file. display( ) ) ,
176+ 1 | 2 => { }
177+ n => tidy_error ! ( bad, "{}: too many trailing newlines ({})" , file. display( ) , n) ,
178+ } ;
168179 } )
169180}
170181
0 commit comments