Skip to content

Commit

Permalink
Sort results (#32)
Browse files Browse the repository at this point in the history
Fixes #31
  • Loading branch information
mutantcornholio authored May 8, 2024
1 parent 0b0d363 commit e3c8ecb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 8 deletions.
12 changes: 11 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ use prdoclib::{
},
common::PRNumber,
config::Config,
prdoc_source::PRDocSource,
prdoc_source::PRDocSource::File,
schema::Schema,
};
use std::cmp::Ordering;
use std::{collections::HashSet, env, path::PathBuf};

/// Main entry point of the cli
Expand Down Expand Up @@ -64,7 +67,7 @@ fn main() -> color_eyre::Result<()> {

Some(SubCommand::Check(cmd_opts)) => {
log::debug!("cmd_opts: {cmd_opts:#?}");
let results: HashSet<CheckResult> = prdoc_dir
let mut results: Vec<CheckResult> = prdoc_dir
.iter()
.flat_map(|dir| {
CheckCmd::run(
Expand All @@ -79,6 +82,13 @@ fn main() -> color_eyre::Result<()> {
})
.collect();

results.sort_by(|a, b| match (&a.0, &b.0) {
(File(path_a), File(path_b)) => path_a.cmp(path_b),
(PRDocSource::Number(num_a), PRDocSource::Number(num_b))
| (PRDocSource::Both(_, num_a), PRDocSource::Both(_, num_b)) => num_a.cmp(num_b),
_ => Ordering::Greater,
});

if !opts.json {
for (src, result) in &results {
if *result {
Expand Down
2 changes: 1 addition & 1 deletion prdoclib/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl CheckCmd {
pub fn global_result(hs: HashSet<CheckResult>) -> bool {
for item in hs.iter() {
if !item.1 {
return false
return false;
}
}

Expand Down
4 changes: 2 additions & 2 deletions prdoclib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ impl Config {
if let Some(config) = config_file {
if PathBuf::from(&config).exists() {
log::debug!("Found config in {config:?}");
return Ok(config)
return Ok(config);
}
}

for name in CONFIG_NAMES {
let candidate = root.join(name);
if candidate.exists() {
log::debug!("Found config in {}", candidate.display());
return Ok(candidate)
return Ok(candidate);
}
}

Expand Down
2 changes: 1 addition & 1 deletion prdoclib/src/doc_filename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl DocFileName {
// First we exclude anything that is not a file
let metadata = std::fs::metadata(candidate.path()).unwrap();
if !metadata.is_file() {
return None
return None;
}

// Fetch the file name
Expand Down
2 changes: 1 addition & 1 deletion prdoclib/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Schema {
if !(validation_result && validation_result_strict) {
log::debug!("validation_result: {validation_result}");
log::debug!("validation_result_strict: {validation_result_strict}");
return Err(PRdocLibError::ValidationErrors(validation))
return Err(PRdocLibError::ValidationErrors(validation));
}

Ok(doc_as_yaml)
Expand Down
4 changes: 2 additions & 2 deletions prdoclib/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn get_project_root() -> io::Result<PathBuf> {
for p in path_ancestors {
let has_cargo = read_dir(p)?.any(|p| p.unwrap().file_name() == "Cargo.lock");
if has_cargo {
return Ok(PathBuf::from(p))
return Ok(PathBuf::from(p));
}
}
Err(io::Error::new(ErrorKind::NotFound, "Ran out of places to find Cargo.toml"))
Expand All @@ -39,7 +39,7 @@ pub(crate) fn get_numbers_from_file(file: &PathBuf) -> error::Result<Vec<ParseRe
/// Return the path of the folder where PRDoc are stored
pub fn get_pr_doc_folder(output_dir: Option<PathBuf>, config: &PRDocConfig) -> PathBuf {
if let Some(path) = output_dir {
return path
return path;
}

config.output_dir.clone()
Expand Down

0 comments on commit e3c8ecb

Please sign in to comment.