Skip to content

Commit 7d4cca5

Browse files
committed
chore: make clippy happy, and have a CI ensuring it stays that way
1 parent 6876274 commit 7d4cca5

File tree

18 files changed

+424
-239
lines changed

18 files changed

+424
-239
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- v*.**
1010
merge_group:
1111
pull_request:
12-
types: [opened, synchronize, reopened]
12+
types: [ opened, synchronize, reopened ]
1313

1414
env:
1515
CARGO_TERM_COLOR: always
@@ -44,6 +44,8 @@ jobs:
4444
- name: Publish dry-run
4545
run: cargo publish --dry-run -p csaf-rs --target=${{ matrix.target.arch }} --verbose
4646
if: ${{ matrix.target.skip-test != true }}
47+
- name: Clippy
48+
run: cargo clippy --target=${{ matrix.target.arch }} --tests --bins --all -- -D warnings
4749
- name: Archive csaf-validator (${{ matrix.target.arch }})
4850
uses: actions/upload-artifact@v4
4951
with:

csaf-rs/build.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ fn main() -> Result<(), BuildError> {
5757
Ok(())
5858
}
5959

60-
fn build(input: &str, output: &str, no_date_time: bool) -> Result<(), BuildError> {
61-
let content = fs::read_to_string(&input)?;
60+
fn build(input: &str, output: &str, no_date_time: bool) -> Result<(), BuildError> {
61+
let content = fs::read_to_string(input)?;
6262
let mut schema_value = serde_json::from_str(&content)?;
6363
if no_date_time {
6464
// Recursively search for "format": "date-time" and remove this format
@@ -69,7 +69,15 @@ fn build(input: &str, output: &str, no_date_time: bool) -> Result<(), BuildError
6969
let mut type_space = TypeSpace::new(TypeSpaceSettings::default().with_struct_builder(true));
7070
type_space.add_root_schema(schema)?;
7171

72-
let content = prettyplease::unparse(&syn::parse2::<syn::File>(type_space.to_stream())?);
72+
let mut content = prettyplease::unparse(&syn::parse2::<syn::File>(type_space.to_stream())?);
73+
content.insert_str(
74+
0,
75+
r#"
76+
#![allow(clippy::clone_on_copy)]
77+
#![allow(clippy::derivable_impls)]
78+
#![allow(clippy::len_zero)]
79+
"#,
80+
);
7381

7482
let mut out_file = Path::new("src").to_path_buf();
7583
out_file.push(output);

csaf-rs/src/csaf/csaf2_0/getter_implementations.rs

Lines changed: 88 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
use crate::csaf::csaf2_0::schema::{Branch, CategoryOfTheRemediation, CommonSecurityAdvisoryFramework, DocumentGenerator, DocumentLevelMetaData, DocumentStatus, Flag, FullProductNameT, HelperToIdentifyTheProduct, Id, Involvement, LabelOfTlp, Note, ProductGroup, ProductStatus, ProductTree, Relationship, Remediation, Revision, RulesForSharingDocument, Score, Threat, Tracking, TrafficLightProtocolTlp, Vulnerability};
2-
use crate::csaf::csaf2_1::schema::{CategoryOfTheRemediation as Remediation21, DocumentStatus as Status21, Epss, LabelOfTlp as Tlp21};
3-
use crate::csaf::getter_traits::{BranchTrait, CsafTrait, DistributionTrait, DocumentTrait, FlagTrait, ProductTrait, GeneratorTrait, InvolvementTrait, MetricTrait, ProductGroupTrait, ProductIdentificationHelperTrait, ProductStatusTrait, ProductTreeTrait, RelationshipTrait, RemediationTrait, RevisionTrait, SharingGroupTrait, ThreatTrait, TlpTrait, TrackingTrait, VulnerabilityTrait, ContentTrait, VulnerabilityIdTrait, NoteTrait, WithGroupIds};
4-
use std::ops::Deref;
5-
use serde::de::Error;
6-
use serde_json::{Map, Value};
1+
use crate::csaf::csaf2_0::schema::{
2+
Branch, CategoryOfTheRemediation, CommonSecurityAdvisoryFramework, DocumentGenerator,
3+
DocumentLevelMetaData, DocumentStatus, Flag, FullProductNameT, HelperToIdentifyTheProduct, Id,
4+
Involvement, LabelOfTlp, Note, ProductGroup, ProductStatus, ProductTree, Relationship,
5+
Remediation, Revision, RulesForSharingDocument, Score, Threat, Tracking,
6+
TrafficLightProtocolTlp, Vulnerability,
7+
};
8+
use crate::csaf::csaf2_1::schema::{
9+
CategoryOfTheRemediation as Remediation21, DocumentStatus as Status21, Epss,
10+
LabelOfTlp as Tlp21,
11+
};
712
use crate::csaf::csaf2_1::ssvc_schema::SsvcV1;
13+
use crate::csaf::getter_traits::{
14+
BranchTrait, ContentTrait, CsafTrait, DistributionTrait, DocumentTrait, FlagTrait,
15+
GeneratorTrait, InvolvementTrait, MetricTrait, NoteTrait, ProductGroupTrait,
16+
ProductIdentificationHelperTrait, ProductStatusTrait, ProductTrait, ProductTreeTrait,
17+
RelationshipTrait, RemediationTrait, RevisionTrait, SharingGroupTrait, ThreatTrait, TlpTrait,
18+
TrackingTrait, VulnerabilityIdTrait, VulnerabilityTrait, WithGroupIds,
19+
};
820
use crate::csaf::validation::ValidationError;
21+
use serde::de::Error;
22+
use serde_json::{Map, Value};
23+
use std::ops::Deref;
924

1025
impl WithGroupIds for Remediation {
11-
fn get_group_ids(&self) -> Option<impl Iterator<Item=&String> + '_> {
12-
self.group_ids.as_ref().map(|g| (*g).iter().map(|x| x.deref()))
26+
fn get_group_ids(&self) -> Option<impl Iterator<Item = &String> + '_> {
27+
self.group_ids
28+
.as_ref()
29+
.map(|g| (*g).iter().map(|x| x.deref()))
1330
}
1431
}
1532

@@ -35,7 +52,9 @@ impl RemediationTrait for Remediation {
3552
}
3653

3754
fn get_product_ids(&self) -> Option<impl Iterator<Item = &String> + '_> {
38-
self.product_ids.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
55+
self.product_ids
56+
.as_ref()
57+
.map(|p| (*p).iter().map(|x| x.deref()))
3958
}
4059

4160
fn get_date(&self) -> &Option<String> {
@@ -45,39 +64,53 @@ impl RemediationTrait for Remediation {
4564

4665
impl ProductStatusTrait for ProductStatus {
4766
fn get_first_affected(&self) -> Option<impl Iterator<Item = &String> + '_> {
48-
self.first_affected.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
67+
self.first_affected
68+
.as_ref()
69+
.map(|p| (*p).iter().map(|x| x.deref()))
4970
}
5071

5172
fn get_first_fixed(&self) -> Option<impl Iterator<Item = &String> + '_> {
52-
self.first_fixed.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
73+
self.first_fixed
74+
.as_ref()
75+
.map(|p| (*p).iter().map(|x| x.deref()))
5376
}
5477

5578
fn get_fixed(&self) -> Option<impl Iterator<Item = &String> + '_> {
5679
self.fixed.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
5780
}
5881

5982
fn get_known_affected(&self) -> Option<impl Iterator<Item = &String> + '_> {
60-
self.known_affected.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
83+
self.known_affected
84+
.as_ref()
85+
.map(|p| (*p).iter().map(|x| x.deref()))
6186
}
6287

6388
fn get_known_not_affected(&self) -> Option<impl Iterator<Item = &String> + '_> {
64-
self.known_not_affected.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
89+
self.known_not_affected
90+
.as_ref()
91+
.map(|p| (*p).iter().map(|x| x.deref()))
6592
}
6693

6794
fn get_last_affected(&self) -> Option<impl Iterator<Item = &String> + '_> {
68-
self.last_affected.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
95+
self.last_affected
96+
.as_ref()
97+
.map(|p| (*p).iter().map(|x| x.deref()))
6998
}
7099

71100
fn get_recommended(&self) -> Option<impl Iterator<Item = &String> + '_> {
72-
self.recommended.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
101+
self.recommended
102+
.as_ref()
103+
.map(|p| (*p).iter().map(|x| x.deref()))
73104
}
74105

75106
fn get_under_investigation(&self) -> Option<impl Iterator<Item = &String> + '_> {
76-
self.under_investigation.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
107+
self.under_investigation
108+
.as_ref()
109+
.map(|p| (*p).iter().map(|x| x.deref()))
77110
}
78111

79112
/// Not specified for CSAF 2.0, so `None`
80-
fn get_unknown(&self) -> Option<impl Iterator<Item=&String> + '_> {
113+
fn get_unknown(&self) -> Option<impl Iterator<Item = &String> + '_> {
81114
None::<std::iter::Empty<&String>>
82115
}
83116
}
@@ -104,7 +137,9 @@ impl ContentTrait for Score {
104137
}
105138

106139
fn get_ssvc_v1(&self) -> Result<SsvcV1, serde_json::Error> {
107-
Err(serde_json::Error::custom("SSVC metrics are not implemented in CSAF 2.0"))
140+
Err(serde_json::Error::custom(
141+
"SSVC metrics are not implemented in CSAF 2.0",
142+
))
108143
}
109144

110145
fn get_cvss_v2(&self) -> Option<&Map<String, Value>> {
@@ -141,13 +176,17 @@ impl ContentTrait for Score {
141176

142177
impl WithGroupIds for Threat {
143178
fn get_group_ids(&self) -> Option<impl Iterator<Item = &String> + '_> {
144-
self.group_ids.as_ref().map(|g| (*g).iter().map(|x| x.deref()))
179+
self.group_ids
180+
.as_ref()
181+
.map(|g| (*g).iter().map(|x| x.deref()))
145182
}
146183
}
147184

148185
impl ThreatTrait for Threat {
149186
fn get_product_ids(&self) -> Option<impl Iterator<Item = &String> + '_> {
150-
self.product_ids.as_ref().map(|p| (*p).iter().map(|x| x.deref()))
187+
self.product_ids
188+
.as_ref()
189+
.map(|p| (*p).iter().map(|x| x.deref()))
151190
}
152191

153192
fn get_date(&self) -> &Option<String> {
@@ -199,15 +238,15 @@ impl VulnerabilityTrait for Vulnerability {
199238
}
200239

201240
fn get_cve(&self) -> Option<&String> {
202-
self.cve.as_ref().map(|x| x.deref())
241+
self.cve.as_deref()
203242
}
204-
243+
205244
fn get_ids(&self) -> &Option<Vec<Self::VulnerabilityIdType>> {
206245
&self.ids
207246
}
208247

209248
fn get_notes(&self) -> Option<&Vec<Self::NoteType>> {
210-
self.notes.as_ref().map(|x| x.deref())
249+
self.notes.as_deref()
211250
}
212251
}
213252

@@ -222,8 +261,10 @@ impl VulnerabilityIdTrait for Id {
222261
}
223262

224263
impl WithGroupIds for Flag {
225-
fn get_group_ids(&self) -> Option<impl Iterator<Item=&String> + '_> {
226-
self.group_ids.as_ref().map(|g| (*g).iter().map(|x| x.deref()))
264+
fn get_group_ids(&self) -> Option<impl Iterator<Item = &String> + '_> {
265+
self.group_ids
266+
.as_ref()
267+
.map(|g| (*g).iter().map(|x| x.deref()))
227268
}
228269
}
229270

@@ -275,15 +316,16 @@ impl DocumentTrait for DocumentLevelMetaData {
275316
fn get_distribution_21(&self) -> Result<&Self::DistributionType, ValidationError> {
276317
match self.distribution.as_ref() {
277318
None => Err(ValidationError {
278-
message: "CSAF 2.1 requires the distribution property, but it is not set.".to_string(),
279-
instance_path: "/document/distribution".to_string()
319+
message: "CSAF 2.1 requires the distribution property, but it is not set."
320+
.to_string(),
321+
instance_path: "/document/distribution".to_string(),
280322
}),
281-
Some(distribution) => Ok(distribution)
323+
Some(distribution) => Ok(distribution),
282324
}
283325
}
284326

285327
fn get_notes(&self) -> Option<&Vec<Self::NoteType>> {
286-
self.notes.as_ref().map(|x| x.deref())
328+
self.notes.as_deref()
287329
}
288330
}
289331

@@ -305,15 +347,15 @@ impl DistributionTrait for RulesForSharingDocument {
305347
match self.tlp.as_ref() {
306348
None => Err(ValidationError {
307349
message: "CSAF 2.1 requires the TLP property, but it is not set.".to_string(),
308-
instance_path: "/document/distribution/sharing_group/tlp".to_string()
350+
instance_path: "/document/distribution/sharing_group/tlp".to_string(),
309351
}),
310-
Some(tlp) => Ok(tlp)
352+
Some(tlp) => Ok(tlp),
311353
}
312354
}
313355
}
314356

315357
impl WithGroupIds for Note {
316-
fn get_group_ids(&self) -> Option<impl Iterator<Item=&String> + '_> {
358+
fn get_group_ids(&self) -> Option<impl Iterator<Item = &String> + '_> {
317359
None::<std::iter::Empty<&String>>
318360
}
319361
}
@@ -408,7 +450,7 @@ impl ProductTreeTrait for ProductTree {
408450
type FullProductNameType = FullProductNameT;
409451

410452
fn get_branches(&self) -> Option<&Vec<Self::BranchType>> {
411-
self.branches.as_ref().map(|branches| branches.deref())
453+
self.branches.as_deref()
412454
}
413455

414456
fn get_product_groups(&self) -> &Vec<Self::ProductGroupType> {
@@ -423,14 +465,17 @@ impl ProductTreeTrait for ProductTree {
423465
&self.full_product_names
424466
}
425467

426-
fn visit_all_products(&self, callback: &mut impl FnMut(&Self::FullProductNameType, &str) -> Result<(), ValidationError>) -> Result<(), ValidationError> {
468+
fn visit_all_products(
469+
&self,
470+
callback: &mut impl FnMut(&Self::FullProductNameType, &str) -> Result<(), ValidationError>,
471+
) -> Result<(), ValidationError> {
427472
self.visit_all_products_generic(callback)
428473
}
429474
}
430475

431476
impl BranchTrait<FullProductNameT> for Branch {
432477
fn get_branches(&self) -> Option<&Vec<Self>> {
433-
self.branches.as_ref().map(|branches| branches.deref())
478+
self.branches.as_deref()
434479
}
435480

436481
fn get_product(&self) -> &Option<FullProductNameT> {
@@ -476,14 +521,18 @@ impl ProductTrait for FullProductNameT {
476521

477522
impl ProductIdentificationHelperTrait for HelperToIdentifyTheProduct {
478523
fn get_purls(&self) -> Option<&[String]> {
479-
self.purl.as_ref().map(|purl| std::slice::from_ref(purl))
524+
self.purl.as_ref().map(std::slice::from_ref)
480525
}
481526

482527
fn get_model_numbers(&self) -> Option<impl Iterator<Item = &String> + '_> {
483-
self.model_numbers.as_ref().map(|v| v.iter().map(|x| x.deref()))
528+
self.model_numbers
529+
.as_ref()
530+
.map(|v| v.iter().map(|x| x.deref()))
484531
}
485532

486533
fn get_serial_numbers(&self) -> Option<impl Iterator<Item = &String> + '_> {
487-
self.serial_numbers.as_ref().map(|v| v.iter().map(|x| x.deref()))
534+
self.serial_numbers
535+
.as_ref()
536+
.map(|v| v.iter().map(|x| x.deref()))
488537
}
489-
}
538+
}

csaf-rs/src/csaf/csaf2_0/loader.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ pub fn load_document(path: &str) -> std::io::Result<CommonSecurityAdvisoryFramew
77
let f = File::open(path)?;
88
let reader = BufReader::new(f);
99
let doc: CommonSecurityAdvisoryFramework = serde_json::from_reader(reader)?;
10-
println!(
11-
"Successfully parsed document '{}'",
12-
doc.document.title.to_string()
13-
);
10+
println!("Successfully parsed document '{}'", *doc.document.title);
1411

1512
Ok(doc)
1613
}

csaf-rs/src/csaf/csaf2_0/schema.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
#![allow(clippy::clone_on_copy)]
3+
#![allow(clippy::derivable_impls)]
4+
#![allow(clippy::len_zero)]
15
/// Error types.
26
pub mod error {
37
/// Error from a TryFrom or FromStr implementation.

0 commit comments

Comments
 (0)