aboutsummaryrefslogtreecommitdiff
path: root/bin/src/explain.rs
blob: de171aafc882f9827fe6e92cc8e8b295fceea3f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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)),
    }
}

pub mod main {

    use crate::{config::Explain as ExplainConfig, err::StatixErr};

    pub fn main(explain_config: ExplainConfig) -> Result<(), StatixErr> {
        let explanation = super::explain(explain_config.target)?;
        println!("{}", explanation);
        Ok(())
    }
}