nu_lint/
lib.rs

1mod ast;
2pub mod cli;
3pub mod config;
4mod context;
5mod effect;
6mod engine;
7mod external_commands;
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 span::{FileSpan, LintSpan};
22use toml::de;
23pub use violation::Violation;
24pub(crate) use violation::{Fix, Replacement};
25
26pub const NU_PARSER_VERSION: &str = env!("NU_PARSER_VERSION");
27
28#[derive(Debug)]
29pub enum LintError {
30    Io { path: PathBuf, source: io::Error },
31    Config { source: de::Error },
32}
33
34impl fmt::Display for LintError {
35    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
36        match self {
37            Self::Io { path, source } => {
38                write!(f, "failed to read '{}': {source}", path.display())
39            }
40            Self::Config { source } => write!(f, "invalid configuration: {source}"),
41        }
42    }
43}
44
45impl Error for LintError {
46    fn source(&self) -> Option<&(dyn Error + 'static)> {
47        match self {
48            Self::Io { source, .. } => Some(source),
49            Self::Config { source } => Some(source),
50        }
51    }
52}