diff --git a/cargo-sbom/src/main.rs b/cargo-sbom/src/main.rs index 969525f..a7be8d4 100644 --- a/cargo-sbom/src/main.rs +++ b/cargo-sbom/src/main.rs @@ -237,11 +237,11 @@ struct Opt { fn main() { if let Err(err) = try_main() { - eprintln!("ERROR: {}", err); + eprintln!("ERROR: {err}"); err .chain() .skip(1) - .for_each(|cause| eprintln!("because: {}", cause)); + .for_each(|cause| eprintln!("because: {cause}")); std::process::exit(1); } } diff --git a/cargo-sbom/src/util/spdx/license.rs b/cargo-sbom/src/util/spdx/license.rs index 760e9f4..c98d36f 100644 --- a/cargo-sbom/src/util/spdx/license.rs +++ b/cargo-sbom/src/util/spdx/license.rs @@ -21,7 +21,7 @@ pub fn normalize_license_string + ToString>( for node in license_expr.iter() { match node { spdx::expression::ExprNode::Req(req) => { - string_stack.push(req.req.license.to_string()); + string_stack.push(req.req.to_string()); op_stack.push(None); } spdx::expression::ExprNode::Op(spdx::expression::Operator::Or) => { @@ -51,7 +51,7 @@ pub fn normalize_license_string + ToString>( })?; op_stack.push(Some(spdx::expression::Operator::Or)); - string_stack.push(format!("{} OR {}", b, a)); + string_stack.push(format!("{b} OR {a}")); } spdx::expression::ExprNode::Op(spdx::expression::Operator::And) => { let mut a = string_stack.pop().ok_or_else(|| { @@ -81,14 +81,14 @@ pub fn normalize_license_string + ToString>( // AND takes precedence, so parenthesize the OR expressions before applying AND if matches!(a_op, Some(spdx::expression::Operator::Or)) { - a = format!("({})", a); + a = format!("({a})"); } if matches!(b_op, Some(spdx::expression::Operator::Or)) { - b = format!("({})", b); + b = format!("({b})"); } op_stack.push(Some(spdx::expression::Operator::And)); - string_stack.push(format!("{} AND {}", b, a)); + string_stack.push(format!("{b} AND {a}")); } } } @@ -104,6 +104,19 @@ pub fn normalize_license_string + ToString>( mod tests { use super::*; + #[test] + fn test_exceptions() { + assert_eq!( + normalize_license_string("Apache-2.0 WITH LLVM-exception").unwrap(), + "Apache-2.0 WITH LLVM-exception" + ); + + assert_eq!( + normalize_license_string("Apache-2.0 WITH LLVM-exception/MIT").unwrap(), + "Apache-2.0 WITH LLVM-exception OR MIT" + ); + } + #[test] fn test_quotation() { assert_eq!( diff --git a/cargo-sbom/src/util/spdx/mod.rs b/cargo-sbom/src/util/spdx/mod.rs index 3e33e45..701f8c7 100644 --- a/cargo-sbom/src/util/spdx/mod.rs +++ b/cargo-sbom/src/util/spdx/mod.rs @@ -249,10 +249,7 @@ pub fn convert( .spdxid("SPDXRef-DOCUMENT") .creation_info(creation_info) .data_license("CC0-1.0") - .document_namespace(format!( - "https://spdx.org/spdxdocs/{}-{}", - name, uuid - )) + .document_namespace(format!("https://spdx.org/spdxdocs/{name}-{uuid}")) .files(files) .name(name) .spdx_version("SPDX-2.3") diff --git a/serde-cyclonedx/build.rs b/serde-cyclonedx/build.rs index e7fdf81..220b626 100644 --- a/serde-cyclonedx/build.rs +++ b/serde-cyclonedx/build.rs @@ -88,11 +88,8 @@ fn process_token_stream(input: proc_macro2::TokenStream) -> syn::File { } fn generate_schema(version_str: &str) -> Result<()> { - println!( - "cargo:rerun-if-changed=schemas/cyclonedx_{}.json", - version_str - ); - let path_str = format!("schemas/cyclonedx_{}.json", version_str); + println!("cargo:rerun-if-changed=schemas/cyclonedx_{version_str}.json",); + let path_str = format!("schemas/cyclonedx_{version_str}.json",); let path = Path::new(&path_str); // Generate the Rust schema struct @@ -105,7 +102,7 @@ fn generate_schema(version_str: &str) -> Result<()> { // Write the struct to the $OUT_DIR/cyclonedx.rs file. let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let mut file = - File::create(out_path.join(format!("cyclonedx_{}.rs", version_str)))?; + File::create(out_path.join(format!("cyclonedx_{version_str}.rs",)))?; file.write_all(prettyplease::unparse(&generated).as_bytes())?; Ok(()) } diff --git a/serde-spdx/build.rs b/serde-spdx/build.rs index 319299c..81d5dc0 100644 --- a/serde-spdx/build.rs +++ b/serde-spdx/build.rs @@ -77,8 +77,8 @@ fn process_token_stream(input: proc_macro2::TokenStream) -> syn::File { } fn generate_schema(version_str: &str) -> Result<()> { - println!("cargo:rerun-if-changed=schemas/spdx_{}.json", version_str); - let path_str = format!("schemas/spdx_{}.json", version_str); + println!("cargo:rerun-if-changed=schemas/spdx_{version_str}.json",); + let path_str = format!("schemas/spdx_{version_str}.json",); let path = Path::new(&path_str); // Generate the Rust schema struct @@ -91,7 +91,7 @@ fn generate_schema(version_str: &str) -> Result<()> { // Write the struct to the $OUT_DIR/spdx.rs file. let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let mut file = - File::create(out_path.join(format!("spdx_{}.rs", version_str)))?; + File::create(out_path.join(format!("spdx_{version_str}.rs",)))?; file.write_all(prettyplease::unparse(&generated).as_bytes())?; Ok(()) } diff --git a/tests/examples_test.rs b/tests/examples_test.rs index dd9b00b..49eb5f7 100644 --- a/tests/examples_test.rs +++ b/tests/examples_test.rs @@ -141,7 +141,7 @@ fn test_cargo_binary_cyclonedx_1_6_example() -> Result<()> { // Ensure we have components and metadata assert!(output_sbom.components.is_some()); assert!(output_sbom.metadata.is_some()); - assert!(output_sbom.components.unwrap().len() > 0); + assert!(!output_sbom.components.unwrap().is_empty()); Ok(()) } @@ -177,7 +177,7 @@ fn test_cargo_binary_cyclonedx_1_5_example() -> Result<()> { // Ensure we have components and metadata assert!(output_sbom.components.is_some()); assert!(output_sbom.metadata.is_some()); - assert!(output_sbom.components.unwrap().len() > 0); + assert!(!output_sbom.components.unwrap().is_empty()); Ok(()) }