From e8c955da4cbb042e6f9b89307d143f5bfa6779fa Mon Sep 17 00:00:00 2001 From: Akshay Date: Sun, 31 Oct 2021 14:35:26 +0530 Subject: add `explain` subcommand and explanations to all lints --- bin/src/explain.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 bin/src/explain.rs (limited to 'bin/src/explain.rs') diff --git a/bin/src/explain.rs b/bin/src/explain.rs new file mode 100644 index 0000000..6aefa7e --- /dev/null +++ b/bin/src/explain.rs @@ -0,0 +1,15 @@ +use crate::err::ExplainErr; + +use lib::LINTS; + +pub fn explain(code: u32) -> Result<&'static str, ExplainErr> { + match code { + 0 => Ok("syntax error"), + _ => LINTS + .values() + .flatten() + .find(|l| l.code() == code) + .map(|l| l.explanation()) + .ok_or(ExplainErr::LintNotFound(code)), + } +} -- cgit v1.2.3