Skip to content

Commit

Permalink
refactor check_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
benluiwj committed Nov 10, 2024
1 parent dc5d3a1 commit 613dacb
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions check_diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl From<io::Error> for GitError {
// will be used in future PRs, just added to make the compiler happy
#[allow(dead_code)]
pub struct CheckDiffRunners {
feature_runner: RustfmtRunner,
src_runner: RustfmtRunner,
pub feature_runner: RustfmtRunner,
pub src_runner: RustfmtRunner,
}

pub struct RustfmtRunner {
Expand All @@ -80,6 +80,33 @@ impl RustfmtRunner {
let binary_version = std::str::from_utf8(&command.stdout)?.trim();
return Ok(binary_version.to_string());
}

// Run rusfmt with the --check flag to see if a diff is produced.
//
// Parameters:
// binary_path: Path to a rustfmt binary
// output_path: Output file path for the diff
// config: Any additional configuration options to pass to rustfmt
//
fn create_diff(&self, output_path: &Path, config: Option<Vec<String>>) {
let config_arg: String = match config {
Some(configs) => {
let mut result = String::new();
result.push(',');
for arg in configs.iter() {
result.push_str(arg.as_str());
result.push(',');
}
result.pop();
result
}
None => String::new(),
};
let config = format!(
"error_on_line_overflow=false,error_on_unformatted=false{}",
config_arg.as_str()
);
}
}

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

// # Run rusfmt with the --check flag to see if a diff is produced.
//
// Parameters:
// $1: Path to a rustfmt binary
// $2: Output file path for the diff
// $3: Any additional configuration options to pass to rustfmt
//
// Globals:
// $OPTIONAL_RUSTFMT_CONFIGS: Optional configs passed to the script from $4
pub fn create_diff(binary_path: PathBuf, output_path: &Path, config: Option<Vec<String>>) {
let config_arg: String = match config {
Some(configs) => {
let mut result = String::new();
result.push(',');
for arg in configs.iter() {
result.push_str(arg.as_str());
result.push(',');
}
result.pop();
result
}
None => String::new(),
};
let config = format!(
"error_on_line_overflow=false,error_on_unformatted=false{}",
config_arg.as_str()
);
}

// Compiles and produces two rustfmt binaries.
// One for the current master, and another for the feature branch
// Parameters:
Expand Down

0 comments on commit 613dacb

Please sign in to comment.