@@ -152,6 +152,8 @@ pub fn check(path: &Path, bad: &mut bool) {
152
152
let mut skip_file_length = contains_ignore_directive ( can_contain, & contents, "filelength" ) ;
153
153
let mut skip_end_whitespace =
154
154
contains_ignore_directive ( can_contain, & contents, "end-whitespace" ) ;
155
+ let mut skip_trailing_newlines =
156
+ contains_ignore_directive ( can_contain, & contents, "trailing-newlines" ) ;
155
157
let mut skip_copyright = contains_ignore_directive ( can_contain, & contents, "copyright" ) ;
156
158
let mut leading_new_lines = false ;
157
159
let mut trailing_new_lines = 0 ;
@@ -214,10 +216,17 @@ pub fn check(path: &Path, bad: &mut bool) {
214
216
if leading_new_lines {
215
217
tidy_error ! ( bad, "{}: leading newline" , file. display( ) ) ;
216
218
}
219
+ let mut err = |msg : & str | {
220
+ tidy_error ! ( bad, "{}: {}" , file. display( ) , msg) ;
221
+ } ;
217
222
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") ,
219
224
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
+ ) ,
221
230
} ;
222
231
if lines > LINES {
223
232
let mut err = |_| {
@@ -247,6 +256,9 @@ pub fn check(path: &Path, bad: &mut bool) {
247
256
if let Directive :: Ignore ( false ) = skip_end_whitespace {
248
257
tidy_error ! ( bad, "{}: ignoring trailing whitespace unnecessarily" , file. display( ) ) ;
249
258
}
259
+ if let Directive :: Ignore ( false ) = skip_trailing_newlines {
260
+ tidy_error ! ( bad, "{}: ignoring trailing newlines unnecessarily" , file. display( ) ) ;
261
+ }
250
262
if let Directive :: Ignore ( false ) = skip_copyright {
251
263
tidy_error ! ( bad, "{}: ignoring copyright unnecessarily" , file. display( ) ) ;
252
264
}
0 commit comments