@@ -152,6 +152,8 @@ pub fn check(path: &Path, bad: &mut bool) {
152152 let mut skip_file_length = contains_ignore_directive ( can_contain, & contents, "filelength" ) ;
153153 let mut skip_end_whitespace =
154154 contains_ignore_directive ( can_contain, & contents, "end-whitespace" ) ;
155+ let mut skip_trailing_newlines =
156+ contains_ignore_directive ( can_contain, & contents, "trailing-newlines" ) ;
155157 let mut skip_copyright = contains_ignore_directive ( can_contain, & contents, "copyright" ) ;
156158 let mut leading_new_lines = false ;
157159 let mut trailing_new_lines = 0 ;
@@ -214,10 +216,17 @@ pub fn check(path: &Path, bad: &mut bool) {
214216 if leading_new_lines {
215217 tidy_error ! ( bad, "{}: leading newline" , file. display( ) ) ;
216218 }
219+ let mut err = |msg : & str | {
220+ tidy_error ! ( bad, "{}: {}" , file. display( ) , msg) ;
221+ } ;
217222 match trailing_new_lines {
218- 0 => tidy_error ! ( bad , "{}: missing trailing newline", file . display ( ) ) ,
223+ 0 => suppressible_tidy_err ! ( err , skip_trailing_newlines , " missing trailing newline") ,
219224 1 => { }
220- n => tidy_error ! ( bad, "{}: too many trailing newlines ({})" , file. display( ) , n) ,
225+ n => suppressible_tidy_err ! (
226+ err,
227+ skip_trailing_newlines,
228+ & format!( "too many trailing newlines ({})" , n)
229+ ) ,
221230 } ;
222231 if lines > LINES {
223232 let mut err = |_| {
@@ -247,6 +256,9 @@ pub fn check(path: &Path, bad: &mut bool) {
247256 if let Directive :: Ignore ( false ) = skip_end_whitespace {
248257 tidy_error ! ( bad, "{}: ignoring trailing whitespace unnecessarily" , file. display( ) ) ;
249258 }
259+ if let Directive :: Ignore ( false ) = skip_trailing_newlines {
260+ tidy_error ! ( bad, "{}: ignoring trailing newlines unnecessarily" , file. display( ) ) ;
261+ }
250262 if let Directive :: Ignore ( false ) = skip_copyright {
251263 tidy_error ! ( bad, "{}: ignoring copyright unnecessarily" , file. display( ) ) ;
252264 }
0 commit comments