Skip to content

Commit c23212a

Browse files
committed
lints: Use enum instead of bool
This is always clearer. Prep for adding another argument to this function that's an effective bool. Signed-off-by: Colin Walters <[email protected]>
1 parent c8e1fb8 commit c23212a

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

lib/src/cli.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,13 @@ async fn run_from_opt(opt: Opt) -> Result<()> {
10481048
if list {
10491049
return lints::lint_list(std::io::stdout().lock());
10501050
}
1051+
let warnings = if fatal_warnings {
1052+
lints::WarningDisposition::FatalWarnings
1053+
} else {
1054+
lints::WarningDisposition::AllowWarnings
1055+
};
10511056
let root = &Dir::open_ambient_dir(rootfs, cap_std::ambient_authority())?;
1052-
lints::lint(root, fatal_warnings, std::io::stdout().lock())?;
1057+
lints::lint(root, warnings, std::io::stdout().lock())?;
10531058
Ok(())
10541059
}
10551060
},

lib/src/lints.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ enum LintType {
6464
Warning,
6565
}
6666

67+
#[derive(Debug, Copy, Clone)]
68+
pub(crate) enum WarningDisposition {
69+
AllowWarnings,
70+
FatalWarnings,
71+
}
72+
6773
#[derive(Debug, Serialize)]
6874
#[serde(rename_all = "kebab-case")]
6975
struct Lint {
@@ -163,7 +169,7 @@ pub(crate) fn lint_list(output: impl std::io::Write) -> Result<()> {
163169
#[context("Linting")]
164170
pub(crate) fn lint(
165171
root: &Dir,
166-
fatal_warnings: bool,
172+
warning_disposition: WarningDisposition,
167173
mut output: impl std::io::Write,
168174
) -> Result<()> {
169175
let mut fatal = 0usize;
@@ -194,7 +200,7 @@ pub(crate) fn lint(
194200
}
195201
}
196202
writeln!(output, "Checks passed: {passed}")?;
197-
let fatal = if fatal_warnings {
203+
let fatal = if matches!(warning_disposition, WarningDisposition::FatalWarnings) {
198204
fatal + warnings
199205
} else {
200206
fatal
@@ -424,10 +430,11 @@ mod tests {
424430
fn test_lint_main() -> Result<()> {
425431
let root = &passing_fixture()?;
426432
let mut out = Vec::new();
427-
lint(root, true, &mut out).unwrap();
433+
let warnings = WarningDisposition::FatalWarnings;
434+
lint(root, warnings, &mut out).unwrap();
428435
root.create_dir_all("var/run/foo")?;
429436
let mut out = Vec::new();
430-
assert!(lint(root, true, &mut out).is_err());
437+
assert!(lint(root, warnings, &mut out).is_err());
431438
Ok(())
432439
}
433440

0 commit comments

Comments
 (0)