1mod ast;
2pub mod cli;
3mod config;
4mod context;
5mod effect;
6mod engine;
7mod fix;
8mod format_conversions;
9mod ignore;
10pub mod log;
11#[cfg(feature = "lsp")]
12mod lsp;
13mod output;
14mod rule;
15mod rules;
16mod span;
17mod violation;
18
19use std::{error::Error, fmt, io, path::PathBuf};
20
21pub use config::{Config, LintLevel};
22pub use engine::LintEngine;
23pub use fix::apply_fixes_iteratively;
24use toml::de;
25use violation::{Fix, Replacement};
26
27pub const NU_PARSER_VERSION: &str = env!("NU_PARSER_VERSION");
28
29#[derive(Debug)]
30pub enum LintError {
31 Io {
32 path: PathBuf,
33 source: io::Error,
34 },
35 Config {
36 source: de::Error,
37 },
38 RuleDoesNotExist {
39 non_existing_id: String,
40 },
41 RuleConflict {
42 rule_a: &'static str,
43 rule_b: &'static str,
44 },
45}
46
47impl fmt::Display for LintError {
48 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
49 match self {
50 Self::Io { path, source } => {
51 write!(f, "failed to read '{}': {source}", path.display())
52 }
53 Self::RuleDoesNotExist { non_existing_id } => write!(
54 f,
55 "Rule declared in config with id `{non_existing_id}` does not exist in this \
56 version."
57 ),
58 Self::Config { source } => write!(f, "invalid configuration: {source}"),
59 Self::RuleConflict { rule_a, rule_b } => {
60 write!(
61 f,
62 "Based on the defaults merged with any configuration file (if present), the \
63 following two rules are both enabled and conclicting: '{rule_a}' and \
64 '{rule_b}'. The linter will not be able to start until you make sure at most \
65 one of both is active. Use the configuration file to override the lint \
66 levels."
67 )
68 }
69 }
70 }
71}
72
73impl Error for LintError {
74 fn source(&self) -> Option<&(dyn Error + 'static)> {
75 match self {
76 Self::Io { source, .. } => Some(source),
77 Self::Config { source } => Some(source),
78 Self::RuleConflict { .. } | Self::RuleDoesNotExist { non_existing_id: _ } => None,
79 }
80 }
81}