Skip to content

Commit 3b0381f

Browse files
committed
clean up
1 parent fc02ccd commit 3b0381f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

check_diff/src/lib.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use diffy::{self};
1+
use diffy;
22
use std::env;
33
use std::fmt::{Debug, Display};
44
use std::io::{self, Write};
@@ -82,8 +82,8 @@ impl Diff {
8282

8383
// will be used in future PRs, just added to make the compiler happy
8484
pub struct CheckDiffRunners {
85-
pub feature_runner: RustfmtRunner,
86-
pub src_runner: RustfmtRunner,
85+
feature_runner: RustfmtRunner,
86+
src_runner: RustfmtRunner,
8787
}
8888

8989
pub struct RustfmtRunner {
@@ -106,6 +106,14 @@ impl CheckDiffRunners {
106106
feature_format,
107107
})
108108
}
109+
110+
pub fn get_feature_runner(self) -> RustfmtRunner {
111+
self.feature_runner
112+
}
113+
114+
pub fn get_src_runner(self) -> RustfmtRunner {
115+
self.src_runner
116+
}
109117
}
110118

111119
impl RustfmtRunner {
@@ -124,10 +132,9 @@ impl RustfmtRunner {
124132
return Ok(binary_version.to_string());
125133
}
126134

127-
// Run rusfmt with the --check flag to see if a diff is produced. Runs on the code specified
135+
// Run rusfmt to see if a diff is produced. Runs on the code specified
128136
//
129137
// Parameters:
130-
// binary_path: Path to a rustfmt binary
131138
// code: Code to run the binary on
132139
// config: Any additional configuration options to pass to rustfmt
133140
//
@@ -156,6 +163,8 @@ impl RustfmtRunner {
156163
}
157164
}
158165

166+
/// Creates a configuration in the following form:
167+
/// <config_name>=<config_val>, <config_name>=<config_val>, ...
159168
fn create_config_arg(config: &Option<Vec<String>>) -> String {
160169
let config_arg: String = match config {
161170
Some(configs) => {
@@ -363,6 +372,7 @@ pub fn compile_rustfmt(
363372
});
364373
}
365374

375+
/// Searches for rust files in the particular path and returns an iterator to them.
366376
pub fn search_for_rs_files(repo: &Path) -> impl Iterator<Item = PathBuf> {
367377
return WalkDir::new(repo).into_iter().filter_map(|e| match e.ok() {
368378
Some(entry) => {
@@ -376,6 +386,8 @@ pub fn search_for_rs_files(repo: &Path) -> impl Iterator<Item = PathBuf> {
376386
});
377387
}
378388

389+
/// Calculates the number of errors when running the compiled binary and the feature binary on the
390+
/// repo specified with the specific configs.
379391
pub fn check_diff(config: Option<Vec<String>>, runners: CheckDiffRunners, repo: &Path) -> i32 {
380392
let mut errors = 0;
381393
let iter = search_for_rs_files(repo);

0 commit comments

Comments
 (0)