Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a stderr file length check to clippy_dev #4100

merged 2 commits into from May 19, 2019
Changes from all commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.


Just for now

@@ -23,6 +23,7 @@ export CARGO_TARGET_DIR=`pwd`/target/

# Perform various checks for lint registration
./util/dev update_lints --check
./util/dev --limit-stderr-length
cargo +nightly fmt --all -- --check

# Check running clippy-driver without cargo
@@ -2,8 +2,9 @@ extern crate clap;
extern crate clippy_dev;
extern crate regex;

use clap::{App, AppSettings, Arg, SubCommand};
use clap::{App, Arg, SubCommand};
use clippy_dev::*;
mod stderr_length_check;

enum UpdateMode {
@@ -13,7 +14,6 @@ enum UpdateMode {

fn main() {
let matches = App::new("Clippy developer tooling")
.about("Updates lint registration and information from the source code")
@@ -36,8 +36,16 @@ fn main() {
.help("Checks that util/dev update_lints has been run. Used on CI."),
.help("Ensures that stderr files do not grow longer than a certain amount of lines."),

if matches.is_present("limit-stderr-length") {
if let Some(matches) = matches.subcommand_matches("update_lints") {
if matches.is_present("print-only") {
@@ -0,0 +1,54 @@
use std::ffi::OsStr;
use walkdir::WalkDir;

use std::fs::File;
use std::io::prelude::*;

// The maximum length allowed for stderr files.
// We limit this because small files are easier to deal with than bigger files.
const LIMIT: usize = 320;

pub fn check() {
let stderr_files = stderr_files();
let exceeding_files = exceeding_stderr_files(stderr_files).collect::<Vec<String>>();

if !exceeding_files.is_empty() {

This comment has been minimized.

Copy link

flip1995 May 17, 2019


Oh the collection is needed because of this. In this case it doesn't matter if we collect inside the function or here. Sorry for that :D

This comment has been minimized.

Copy link

phansch May 17, 2019

Author Member

I think it's still better to collect at the call site rather than in the function itself, so it's fine 👍

eprintln!("Error: stderr files exceeding limit of {} lines:", LIMIT);
for path in exceeding_files {
println!("{}", path);

fn exceeding_stderr_files(files: impl Iterator<Item = walkdir::DirEntry>) -> impl Iterator<Item = String> {
.filter_map(|file| {
let path = file.path().to_str().expect("Could not convert path to str").to_string();
let linecount = count_linenumbers(&path);
if linecount > LIMIT {
} else {

fn stderr_files() -> impl Iterator<Item = walkdir::DirEntry> {
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
.filter(|f| f.path().extension() == Some(OsStr::new("stderr")))

fn count_linenumbers(filepath: &str) -> usize {
if let Ok(mut file) = File::open(filepath) {
let mut content = String::new();
file.read_to_string(&mut content).expect("Failed to read file?");
} else {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.