Skip to content

Commit

Permalink
Auto merge of #60167 - varkor:tidy-filelength, r=matthewjasper
Browse files Browse the repository at this point in the history
Add a tidy check for files with over 3,000 lines

Files with a large number of lines can cause issues in GitHub (e.g. #60015) and also tend to be indicative of opportunities to refactor into less monolithic structures.

This adds a new check to tidy to warn against files that have more than 3,000 lines, as suggested in #60015 (comment). (This number was chosen fairly arbitrarily as a reasonable indicator of size.) This check can be ignored with `// ignore-tidy-filelength`.

Existing files with greater than 3,000 lines currently ignore the check, but this helps us spot when files are getting too large. (We might try to split up all files larger than this in the future, as in #60015).
  • Loading branch information
bors committed Apr 26, 2019
2 parents 180edc2 + 8c30687 commit e8310a7
Show file tree
Hide file tree
Showing 26 changed files with 76 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/liballoc/collections/vec_deque.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! A double-ended queue implemented with a growable ring buffer.
//!
//! This queue has `O(1)` amortized inserts and removals from both ends of the
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Numeric traits and functions for the built-in numeric types.
#![stable(feature = "rust1", since = "1.0.0")]
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Manually manage memory through raw pointers.
//!
//! *[See also the pointer primitive types](../../std/primitive.pointer.html).*
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/slice/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Slice management and manipulation.
//!
//! For more details see [`std::slice`].
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! String manipulation.
//!
//! For more details, see the `std::str` module.
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/hir/lowering.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Lowers the AST to the HIR.
//!
//! Since the AST and HIR are fairly similar, this is mostly a simple procedure,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! MIR datatypes and passes. See the [rustc guide] for more info.
//!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/mir/index.html
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Contains infrastructure for configuring the compiler, including parsing
//! command line options.
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Candidate selection. See the [rustc guide] for more information on how this works.
//!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/traits/resolution.html#selection
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Type context book-keeping.
use crate::arena::Arena;
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/ty/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

#![allow(usage_of_ty_tykind)]

pub use self::Variance::*;
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_apfloat/tests/ieee.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

use rustc_apfloat::{Category, ExpInt, IEK_INF, IEK_NAN, IEK_ZERO};
use rustc_apfloat::{Float, FloatConvert, ParseError, Round, Status};
use rustc_apfloat::ieee::{Half, Single, Double, Quad, X87DoubleExtended};
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]

#![feature(crate_visibility_modifier)]
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

/*!

# typeck: check phase
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_typeck/error_codes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// ignore-tidy-linelength
// ignore-tidy-filelength

#![allow(non_snake_case)]

register_long_diagnostics! {
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! This module contains the "cleaned" pieces of the AST, and the functions
//! that clean them.

Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Rustdoc's HTML rendering module.
//!
//! This modules contains the bulk of the logic necessary for rendering a
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

use self::Entry::*;

use hashbrown::hash_map as base;
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Filesystem manipulation operations.
//!
//! This module contains basic methods to manipulate the contents of the local
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Cross-platform path manipulation.
//!
//! This module provides two types, [`PathBuf`] and [`Path`][`Path`] (akin to [`String`]
Expand Down
2 changes: 2 additions & 0 deletions src/libstd/sync/mpsc/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

//! Multi-producer, single-consumer FIFO queue communication primitives.
//!
//! This module provides message-based communication over channels, concretely
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

use crate::ast::{AngleBracketedArgs, AsyncArgument, ParenthesizedArgs, AttrStyle, BareFnTy};
use crate::ast::{GenericBound, TraitBoundModifier};
use crate::ast::Unsafety;
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

use crate::ast::{self, BlockCheckMode, PatKind, RangeEnd, RangeSyntax};
use crate::ast::{SelfKind, GenericBound, TraitBoundModifier};
use crate::ast::{Attribute, MacDelimiter, GenericArg};
Expand Down
4 changes: 4 additions & 0 deletions src/test/run-pass/issues/issue-29466.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// ignore-tidy-filelength
//
// run-pass

#![allow(unused_variables)]

macro_rules! m(
($e1:expr => $e2:expr) => ({ $e1 })
);
Expand Down
2 changes: 2 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// ignore-tidy-filelength

use crate::common::CompareMode;
use crate::common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
use crate::common::{output_base_dir, output_base_name, output_testname_unique};
Expand Down
27 changes: 24 additions & 3 deletions src/tools/tidy/src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,6 +19,8 @@ use std::path::Path;

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
Expand Down Expand Up @@ -139,19 +142,21 @@ 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);
};
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)
);
}
Expand Down Expand Up @@ -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());
Expand All @@ -206,16 +212,31 @@ pub fn check(path: &Path, bad: &mut bool) {
1 => {}
n => tidy_error!(bad, "{}: too many trailing newlines ({})", file.display(), n),
};
if lines > LINES {
let mut err = |_| {
tidy_error!(
bad,
"{}: too many lines ({}) (add `// \
ignore-tidy-filelength` to the file to suppress this error)",
file.display(),
lines
);
};
suppressible_tidy_err!(err, skip_file_length, "");
}

if let Directive::Ignore(false) = skip_cr {
tidy_error!(bad, "{}: ignoring CR characters unnecessarily", file.display());
}
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());
}
Expand Down

0 comments on commit e8310a7

Please sign in to comment.