Skip to content

Commit 613dacb

Browse files
committed
refactor check_diff
1 parent dc5d3a1 commit 613dacb

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

check_diff/src/lib.rs

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ impl From<io::Error> for GitError {
5656
// will be used in future PRs, just added to make the compiler happy
5757
#[allow(dead_code)]
5858
pub struct CheckDiffRunners {
59-
feature_runner: RustfmtRunner,
60-
src_runner: RustfmtRunner,
59+
pub feature_runner: RustfmtRunner,
60+
pub src_runner: RustfmtRunner,
6161
}
6262

6363
pub struct RustfmtRunner {
@@ -80,6 +80,33 @@ impl RustfmtRunner {
8080
let binary_version = std::str::from_utf8(&command.stdout)?.trim();
8181
return Ok(binary_version.to_string());
8282
}
83+
84+
// Run rusfmt with the --check flag to see if a diff is produced.
85+
//
86+
// Parameters:
87+
// binary_path: Path to a rustfmt binary
88+
// output_path: Output file path for the diff
89+
// config: Any additional configuration options to pass to rustfmt
90+
//
91+
fn create_diff(&self, output_path: &Path, config: Option<Vec<String>>) {
92+
let config_arg: String = match config {
93+
Some(configs) => {
94+
let mut result = String::new();
95+
result.push(',');
96+
for arg in configs.iter() {
97+
result.push_str(arg.as_str());
98+
result.push(',');
99+
}
100+
result.pop();
101+
result
102+
}
103+
None => String::new(),
104+
};
105+
let config = format!(
106+
"error_on_line_overflow=false,error_on_unformatted=false{}",
107+
config_arg.as_str()
108+
);
109+
}
83110
}
84111

85112
/// Clone a git repository
@@ -227,35 +254,6 @@ pub fn build_rustfmt_from_src(binary_path: PathBuf) -> Result<RustfmtRunner, Che
227254
});
228255
}
229256

230-
// # Run rusfmt with the --check flag to see if a diff is produced.
231-
//
232-
// Parameters:
233-
// $1: Path to a rustfmt binary
234-
// $2: Output file path for the diff
235-
// $3: Any additional configuration options to pass to rustfmt
236-
//
237-
// Globals:
238-
// $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4
239-
pub fn create_diff(binary_path: PathBuf, output_path: &Path, config: Option<Vec<String>>) {
240-
let config_arg: String = match config {
241-
Some(configs) => {
242-
let mut result = String::new();
243-
result.push(',');
244-
for arg in configs.iter() {
245-
result.push_str(arg.as_str());
246-
result.push(',');
247-
}
248-
result.pop();
249-
result
250-
}
251-
None => String::new(),
252-
};
253-
let config = format!(
254-
"error_on_line_overflow=false,error_on_unformatted=false{}",
255-
config_arg.as_str()
256-
);
257-
}
258-
259257
// Compiles and produces two rustfmt binaries.
260258
// One for the current master, and another for the feature branch
261259
// Parameters:

0 commit comments

Comments
 (0)