@@ -130,6 +130,7 @@ pub fn check(path: &Path, bad: &mut bool) {
130
130
let skip_tab = contents. contains ( "ignore-tidy-tab" ) ;
131
131
let skip_length = contents. contains ( "ignore-tidy-linelength" ) ;
132
132
let skip_end_whitespace = contents. contains ( "ignore-tidy-end-whitespace" ) ;
133
+ let mut trailing_new_lines = 0 ;
133
134
for ( i, line) in contents. split ( "\n " ) . enumerate ( ) {
134
135
let mut err = |msg : & str | {
135
136
tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , i + 1 , msg) ;
@@ -161,10 +162,20 @@ pub fn check(path: &Path, bad: &mut bool) {
161
162
if filename. ends_with ( ".cpp" ) && line. contains ( "llvm_unreachable" ) {
162
163
err ( LLVM_UNREACHABLE_INFO ) ;
163
164
}
165
+ if line. is_empty ( ) {
166
+ trailing_new_lines += 1 ;
167
+ } else {
168
+ trailing_new_lines = 0 ;
169
+ }
164
170
}
165
171
if !licenseck ( file, & contents) {
166
172
tidy_error ! ( bad, "{}: incorrect license" , file. display( ) ) ;
167
173
}
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
+ } ;
168
179
} )
169
180
}
170
181
0 commit comments