nu_lint/
lib.rs

1mod alternatives;
2mod ast;
3pub mod cli;
4pub mod config;
5mod context;
6mod effect;
7mod engine;
8pub mod fix;
9pub mod log;
10pub mod lsp;
11pub mod output;
12mod rule;
13mod rules;
14mod span;
15mod violation;
16
17use std::{error::Error, fmt, io, path::PathBuf};
18
19pub use config::{Config, LintLevel};
20pub use engine::LintEngine;
21pub use output::{
22    JsonFix, JsonOutput, JsonReplacement, JsonViolation, Summary, format_json, format_text,
23};
24pub use span::{FileSpan, GlobalSpan, LintSpan};
25use toml::de;
26pub use violation::Violation;
27pub(crate) use violation::{Fix, Replacement};
28
29pub const NU_PARSER_VERSION: &str = env!("NU_PARSER_VERSION");
30
31#[derive(Debug)]
32pub enum LintError {
33    Io { path: PathBuf, source: io::Error },
34    Config { source: de::Error },
35}
36
37impl fmt::Display for LintError {
38    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
39        match self {
40            Self::Io { path, source } => {
41                write!(f, "failed to read '{}': {source}", path.display())
42            }
43            Self::Config { source } => write!(f, "invalid configuration: {source}"),
44        }
45    }
46}
47
48impl Error for LintError {
49    fn source(&self) -> Option<&(dyn Error + 'static)> {
50        match self {
51            Self::Io { source, .. } => Some(source),
52            Self::Config { source } => Some(source),
53        }
54    }
55}