Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Nov 15, 2024
1 parent f3d8c34 commit fcb4b3b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rustflags = [
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
Expand Down Expand Up @@ -75,5 +74,6 @@ rustflags = [
"-Wfuture_incompatible",
"-Wnonstandard_style",
"-Wrust_2018_idioms",
"-Wunexpected_cfgs",
# END - Embark standard lints v6 for Rust 1.55+
]
33 changes: 15 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@ pub struct Krate(pub cm::Package);

impl Krate {
fn get_license_expression(&self) -> licenses::LicenseInfo {
match &self.0.license {
Some(license_field) => {
//. Reasons this can fail:
// * Empty! The rust crate used to validate this field has a bug
// https://github.com/rust-lang-nursery/license-exprs/issues/23
// * It also just does basic lexing, so parens, duplicate operators,
// unpaired exceptions etc can all fail validation

match spdx::Expression::parse(license_field) {
Ok(validated) => licenses::LicenseInfo::Expr(validated),
Err(err) => {
log::error!("unable to parse license expression for '{}': {}", self, err);
licenses::LicenseInfo::Unknown
}
if let Some(license_field) = &self.0.license {
//. Reasons this can fail:
// * Empty! The rust crate used to validate this field has a bug
// https://github.com/rust-lang-nursery/license-exprs/issues/23
// * It also just does basic lexing, so parens, duplicate operators,
// unpaired exceptions etc can all fail validation

match spdx::Expression::parse(license_field) {
Ok(validated) => licenses::LicenseInfo::Expr(validated),
Err(err) => {
log::error!("unable to parse license expression for '{self}': {err}");
licenses::LicenseInfo::Unknown
}
}
None => {
log::warn!("crate '{}' doesn't have a license field", self);
licenses::LicenseInfo::Unknown
}
} else {
log::warn!("crate '{self}' doesn't have a license field");
licenses::LicenseInfo::Unknown
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/licenses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,15 @@ impl Gatherer {
license_files.sort();

let mut expr = None;
license_files.retain(|lf| match &expr {
Some(cur) => {
license_files.retain(|lf| {
if let Some(cur) = &expr {
if *cur != lf.license_expr {
expr = Some(lf.license_expr.clone());
true
} else {
false
}
}
None => {
} else {
expr = Some(lf.license_expr.clone());
true
}
Expand Down
25 changes: 11 additions & 14 deletions src/licenses/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,20 +205,17 @@ impl GitCache {
format!("crate '{krate}' with registry source does not have a 'repository'")
})?;

let sha1 = match commit_override {
Some(co) => {
log::debug!("using commit override '{co}' for crate '{krate}'");
co.clone()
}
None => {
let vcs_info_path = krate
.manifest_path
.parent()
.unwrap()
.join(".cargo_vcs_info.json");

Self::parse_vcs_info(&vcs_info_path)?.git.sha1
}
let sha1 = if let Some(co) = commit_override {
log::debug!("using commit override '{co}' for crate '{krate}'");
co.clone()
} else {
let vcs_info_path = krate
.manifest_path
.parent()
.unwrap()
.join(".cargo_vcs_info.json");

Self::parse_vcs_info(&vcs_info_path)?.git.sha1
};

let hash = {
Expand Down

0 comments on commit fcb4b3b

Please sign in to comment.