|
10 | 10 | //! * No unexplained ` ```ignore ` or ` ```rust,ignore ` doc tests. |
11 | 11 | //! |
12 | 12 | //! A number of these checks can be opted-out of with various directives like |
13 | | -//! `// ignore-tidy-linelength`. |
| 13 | +//! `// ignore-tidy-copyright`. |
14 | 14 |
|
15 | 15 | use std::fs::File; |
16 | 16 | use std::io::prelude::*; |
@@ -119,13 +119,16 @@ pub fn check(path: &Path, bad: &mut bool) { |
119 | 119 | let skip_copyright = contains_ignore_directive(&contents, "copyright"); |
120 | 120 | let mut leading_new_lines = false; |
121 | 121 | let mut trailing_new_lines = 0; |
| 122 | + let mut contained_long_line = false; |
122 | 123 | for (i, line) in contents.split('\n').enumerate() { |
123 | 124 | let mut err = |msg: &str| { |
124 | 125 | tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg); |
125 | 126 | }; |
126 | | - if !skip_length && line.chars().count() > COLS |
127 | | - && !long_line_is_ok(line) { |
| 127 | + if line.chars().count() > COLS && !long_line_is_ok(line) { |
| 128 | + contained_long_line = true; |
| 129 | + if !skip_length { |
128 | 130 | err(&format!("line longer than {} chars", COLS)); |
| 131 | + } |
129 | 132 | } |
130 | 133 | if !skip_tab && line.contains('\t') { |
131 | 134 | err("tab character"); |
@@ -174,5 +177,8 @@ pub fn check(path: &Path, bad: &mut bool) { |
174 | 177 | 1 => {} |
175 | 178 | n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n), |
176 | 179 | }; |
| 180 | + if !contained_long_line && skip_length { |
| 181 | + tidy_error!(bad, "{}: ignoring line length unnecessarily", file.display()); |
| 182 | + } |
177 | 183 | }) |
178 | 184 | } |
0 commit comments