Skip to content

Commit 51b2ecf

Browse files
committed
Tidy warn on ignored line length when lines are not too long
1 parent 33f0a37 commit 51b2ecf

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/tools/tidy/src/style.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! * No unexplained ` ```ignore ` or ` ```rust,ignore ` doc tests.
1111
//!
1212
//! A number of these checks can be opted-out of with various directives like
13-
//! `// ignore-tidy-linelength`.
13+
//! `// ignore-tidy-copyright`.
1414
1515
use std::fs::File;
1616
use std::io::prelude::*;
@@ -119,13 +119,16 @@ pub fn check(path: &Path, bad: &mut bool) {
119119
let skip_copyright = contains_ignore_directive(&contents, "copyright");
120120
let mut leading_new_lines = false;
121121
let mut trailing_new_lines = 0;
122+
let mut contained_long_line = false;
122123
for (i, line) in contents.split('\n').enumerate() {
123124
let mut err = |msg: &str| {
124125
tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
125126
};
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 {
128130
err(&format!("line longer than {} chars", COLS));
131+
}
129132
}
130133
if !skip_tab && line.contains('\t') {
131134
err("tab character");
@@ -174,5 +177,8 @@ pub fn check(path: &Path, bad: &mut bool) {
174177
1 => {}
175178
n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n),
176179
};
180+
if !contained_long_line && skip_length {
181+
tidy_error!(bad, "{}: ignoring line length unnecessarily", file.display());
182+
}
177183
})
178184
}

0 commit comments

Comments
 (0)