Skip to content

Commit bcce8f9

Browse files
committed
Make section optional, fixes #11
1 parent cf856a1 commit bcce8f9

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

fontspector-checkapi/src/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'a> Check<'a> {
6666
&'a self,
6767
fn_result: CheckFnResult,
6868
file: Option<&'a Testable>,
69-
section: &str,
69+
section: Option<&str>,
7070
) -> CheckResult {
7171
let subresults = match fn_result {
7272
Ok(results) => results.collect::<Vec<_>>(),
@@ -88,7 +88,7 @@ impl<'a> Check<'a> {
8888
&'a self,
8989
testable: &'a TestableType,
9090
context: &Context,
91-
section: &str,
91+
section: Option<&str>,
9292
) -> Option<CheckResult> {
9393
match (&self.implementation, testable) {
9494
(CheckImplementation::CheckAll(_), TestableType::Single(_)) => None,

fontspector-checkapi/src/checkresult.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct CheckResult {
3232
/// The file which was checked; if None, the check was run on all files
3333
pub filename: Option<String>,
3434
/// The section of the profile this check belongs to
35-
pub section: String,
35+
pub section: Option<String>,
3636
/// The individual results of the check
3737
pub subresults: Vec<Status>,
3838
/// If hotfixing was attempted, the result of the hotfix
@@ -68,15 +68,15 @@ impl CheckResult {
6868
pub fn new(
6969
check: &Check,
7070
filename: Option<&str>,
71-
section: &str,
71+
section: Option<&str>,
7272
subresults: Vec<Status>,
7373
) -> Self {
7474
Self {
7575
check_id: check.id.to_string(),
7676
check_name: check.title.to_string(),
7777
check_rationale: check.rationale.to_string(),
7878
filename: filename.map(|x| x.to_string()),
79-
section: section.to_string(),
79+
section: section.map(|x| x.to_string()),
8080
subresults,
8181
hotfix_result: None,
8282
sourcefix_result: None,

fontspector-cli/src/main.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ fn main() {
192192
#[allow(clippy::unwrap_used)] // We check for is_some before unwrapping
193193
let results: RunResults = checkorder_iterator
194194
.map(|(sectionname, testable, check, context)| {
195-
(testable, check, check.run(testable, context, sectionname))
195+
(
196+
testable,
197+
check,
198+
check.run(testable, context, Some(sectionname)),
199+
)
196200
})
197201
.filter(|(_, _, result)| result.is_some())
198202
.map(|(testable, check, result)| (testable, check, result.unwrap()))

fontspector-cli/src/reporters/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ impl RunResults {
4242
pub fn organize(&self) -> OrganisedResults {
4343
let mut organised_results: OrganisedResults = HashMap::new();
4444
for checkresult in self.iter() {
45-
// let filename = testable.filename.clone();
4645
let section = organised_results
4746
.entry(
4847
checkresult
@@ -51,7 +50,14 @@ impl RunResults {
5150
.unwrap_or("All fonts".to_string()),
5251
)
5352
.or_default();
54-
let results = section.entry(checkresult.section.clone()).or_default();
53+
let results = section
54+
.entry(
55+
checkresult
56+
.section
57+
.clone()
58+
.unwrap_or("No section".to_string()),
59+
)
60+
.or_default();
5561
results.push(checkresult.clone());
5662
}
5763
organised_results

fontspector-web/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ pub fn check_fonts(fonts: &JsValue) -> Result<String, JsValue> {
5656
let results: Vec<CheckResult> = checkorder
5757
.iter()
5858
.map(|(sectionname, testable, check, context)| {
59-
(testable, check, check.run(testable, context, sectionname))
59+
(
60+
testable,
61+
check,
62+
check.run(testable, context, Some(sectionname)),
63+
)
6064
})
6165
.flat_map(|(_, _, result)| result)
6266
.collect();

0 commit comments

Comments
 (0)