nu_lint/
lib.rs

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