From 51b2ecf78add935bd5192f15aa65b2e83975ed26 Mon Sep 17 00:00:00 2001 From: varkor Date: Mon, 22 Apr 2019 16:15:39 +0100 Subject: [PATCH] Tidy warn on ignored line length when lines are not too long --- src/tools/tidy/src/style.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tools/tidy/src/style.rs b/src/tools/tidy/src/style.rs index ae4ddd825dc..b373725617c 100644 --- a/src/tools/tidy/src/style.rs +++ b/src/tools/tidy/src/style.rs @@ -10,7 +10,7 @@ //! * No unexplained ` ```ignore ` or ` ```rust,ignore ` doc tests. //! //! A number of these checks can be opted-out of with various directives like -//! `// ignore-tidy-linelength`. +//! `// ignore-tidy-copyright`. use std::fs::File; use std::io::prelude::*; @@ -119,13 +119,16 @@ pub fn check(path: &Path, bad: &mut bool) { let skip_copyright = contains_ignore_directive(&contents, "copyright"); let mut leading_new_lines = false; let mut trailing_new_lines = 0; + let mut contained_long_line = false; for (i, line) in contents.split('\n').enumerate() { let mut err = |msg: &str| { tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg); }; - if !skip_length && line.chars().count() > COLS - && !long_line_is_ok(line) { + if line.chars().count() > COLS && !long_line_is_ok(line) { + contained_long_line = true; + if !skip_length { err(&format!("line longer than {} chars", COLS)); + } } if !skip_tab && line.contains('\t') { err("tab character"); @@ -174,5 +177,8 @@ pub fn check(path: &Path, bad: &mut bool) { 1 => {} n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n), }; + if !contained_long_line && skip_length { + tidy_error!(bad, "{}: ignoring line length unnecessarily", file.display()); + } }) }