Skip to content

Commit 2360a7c

Browse files
committed
cargo clippy dev: collecting one-line clippy warnings works now
1 parent 69c0757 commit 2360a7c

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

clippy_dev/src/crater.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,26 @@ impl KrateSource {
5757
Krate {
5858
version: self.version.clone(),
5959
name: self.name.clone(),
60-
path: extract_dir.join(format!("{}-{}/", self.name, self.version))
60+
path: extract_dir.join(format!("{}-{}/", self.name, self.version)),
6161
}
6262
}
6363
}
6464

6565
impl Krate {
66-
fn run_clippy_lints(&self, cargo_clippy_path: &PathBuf) -> String {
66+
fn run_clippy_lints(&self, cargo_clippy_path: &PathBuf) -> String {
6767
let cargo_clippy_path = std::fs::canonicalize(cargo_clippy_path).unwrap();
6868
let project_root = &self.path;
6969
dbg!(&cargo_clippy_path);
7070
dbg!(&project_root);
7171

72-
let output = std::process::Command::new(cargo_clippy_path).current_dir(project_root).output();
73-
dbg!(&output);
74-
let output = String::from_utf8_lossy(&output.unwrap().stderr).into_owned();
75-
dbg!(&output);
72+
let output = std::process::Command::new(cargo_clippy_path)
73+
.args(&["--", "--message-format=short","--", "--cap-lints=warn",])
74+
.current_dir(project_root)
75+
.output();
76+
let output: String = String::from_utf8_lossy(&output.unwrap().stderr).lines().filter(|line|line.contains(": warning: ")).collect();
77+
// output.lines().for_each(|l| println!("{}", l));
78+
//dbg!(&output);
79+
7680
output
7781
}
7882
}
@@ -90,7 +94,7 @@ pub fn run() {
9094
let clippy_driver_path: PathBuf = PathBuf::from("target/debug/clippy-driver");
9195

9296
// crates we want to check:
93-
let krates: Vec<KrateSource> = vec![KrateSource::new("regex", "1.4.2"), KrateSource::new("cargo", "0.49.0"), ];
97+
let krates: Vec<KrateSource> = vec![KrateSource::new("regex", "1.4.2"), KrateSource::new("cargo", "0.49.0")];
9498

9599
println!("Compiling clippy...");
96100
build_clippy();
@@ -106,12 +110,13 @@ pub fn run() {
106110
clippy_driver_path.is_file(),
107111
"target/debug/clippy-driver binary not found! {}",
108112
clippy_driver_path.display()
109-
);
113+
);
110114

111115
// download and extract the crates, then run clippy on them and collect clippys warnings
112-
let _clippy_lint_results: Vec<String> = krates
116+
let clippy_lint_results: Vec<String> = krates
113117
.into_iter()
114118
.map(|krate| krate.download_and_extract())
115119
.map(|krate| krate.run_clippy_lints(&cargo_clippy_path))
116120
.collect::<Vec<String>>();
121+
dbg!(clippy_lint_results);
117122
}

0 commit comments

Comments
 (0)