]> git.lizzy.rs Git - rust.git/commitdiff
Add a tidy test for line count
authorvarkor <github@varkor.com>
Mon, 22 Apr 2019 14:28:48 +0000 (15:28 +0100)
committervarkor <github@varkor.com>
Thu, 25 Apr 2019 20:38:47 +0000 (21:38 +0100)
src/tools/tidy/src/style.rs

index 9ab88d6e9aeac8049dc68c1c39a7b4325319cf25..4de7e580b0000316a8cb671250860ead325719ee 100644 (file)
@@ -3,6 +3,7 @@
 //! Example checks are:
 //!
 //! * No lines over 100 characters.
+//! * No files with over 3000 lines.
 //! * No tabs.
 //! * No trailing whitespace.
 //! * No CR characters.
@@ -18,6 +19,8 @@
 
 const COLS: usize = 100;
 
+const LINES: usize = 3000;
+
 const UNEXPLAINED_IGNORE_DOCTEST_INFO: &str = r#"unexplained "```ignore" doctest; try one:
 
 * make the test actually pass, by adding necessary imports and declarations, or
@@ -139,11 +142,13 @@ pub fn check(path: &Path, bad: &mut bool) {
 
         let mut skip_cr = contains_ignore_directive(&contents, "cr");
         let mut skip_tab = contains_ignore_directive(&contents, "tab");
-        let mut skip_length = contains_ignore_directive(&contents, "linelength");
+        let mut skip_line_length = contains_ignore_directive(&contents, "linelength");
+        let mut skip_file_length = contains_ignore_directive(&contents, "filelength");
         let mut skip_end_whitespace = contains_ignore_directive(&contents, "end-whitespace");
         let mut skip_copyright = contains_ignore_directive(&contents, "copyright");
         let mut leading_new_lines = false;
         let mut trailing_new_lines = 0;
+        let mut lines = 0;
         for (i, line) in contents.split('\n').enumerate() {
             let mut err = |msg: &str| {
                 tidy_error!(bad, "{}:{}: {}", file.display(), i + 1, msg);
@@ -151,7 +156,7 @@ pub fn check(path: &Path, bad: &mut bool) {
             if line.chars().count() > COLS && !long_line_is_ok(line) {
                 suppressible_tidy_err!(
                     err,
-                    skip_length,
+                    skip_line_length,
                     &format!("line longer than {} chars", COLS)
                 );
             }
@@ -197,6 +202,7 @@ pub fn check(path: &Path, bad: &mut bool) {
             } else {
                 trailing_new_lines = 0;
             }
+            lines = i;
         }
         if leading_new_lines {
             tidy_error!(bad, "{}: leading newline", file.display());
@@ -206,6 +212,9 @@ pub fn check(path: &Path, bad: &mut bool) {
             1 => {}
             n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n),
         };
+        if !skip_file_length && lines > LINES {
+            tidy_error!(bad, "{}: too many lines ({})", file.display(), lines);
+        }
 
         if let Directive::Ignore(false) = skip_cr {
             tidy_error!(bad, "{}: ignoring CR characters unnecessarily", file.display());
@@ -213,9 +222,12 @@ pub fn check(path: &Path, bad: &mut bool) {
         if let Directive::Ignore(false) = skip_tab {
             tidy_error!(bad, "{}: ignoring tab characters unnecessarily", file.display());
         }
-        if let Directive::Ignore(false) = skip_length {
+        if let Directive::Ignore(false) = skip_line_length {
             tidy_error!(bad, "{}: ignoring line length unnecessarily", file.display());
         }
+        if let Directive::Ignore(false) = skip_file_length {
+            tidy_error!(bad, "{}: ignoring file length unnecessarily", file.display());
+        }
         if let Directive::Ignore(false) = skip_end_whitespace {
             tidy_error!(bad, "{}: ignoring trailing whitespace unnecessarily", file.display());
         }