aboutsummaryrefslogtreecommitdiff
path: root/bin/src/explain.rs
blob: bcb8eed9ddfe5fc6aef206f2d574aff48bf6ec8f (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
use crate::{err::ExplainErr, utils};

pub fn explain(code: u32) -> Result<&'static str, ExplainErr> {
    let lints = utils::lint_map();
    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(())
    }
}