#![allow(clippy::unwrap_used)]
#![allow(clippy::indexing_slicing)]
pub mod aliaser; pub mod analyzer;
pub mod deduplicator;
pub mod nondeterminism; pub mod purifier;
pub mod quoter;
use std::path::{Path, PathBuf};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConfigType {
Bashrc,
BashProfile,
Zshrc,
Zprofile,
Profile,
Generic,
}
impl ConfigType {
pub fn from_path(path: &Path) -> Self {
let filename = path.file_name().and_then(|s| s.to_str()).unwrap_or("");
match filename {
".bashrc" | "bashrc" => ConfigType::Bashrc,
".bash_profile" | "bash_profile" => ConfigType::BashProfile,
".zshrc" | "zshrc" => ConfigType::Zshrc,
".zprofile" | "zprofile" => ConfigType::Zprofile,
".profile" | "profile" => ConfigType::Profile,
_ => ConfigType::Generic,
}
}
pub fn expected_shell(&self) -> &'static str {
match self {
ConfigType::Bashrc | ConfigType::BashProfile => "bash",
ConfigType::Zshrc | ConfigType::Zprofile => "zsh",
ConfigType::Profile => "sh",
ConfigType::Generic => "sh",
}
}
}
#[derive(Debug, Clone)]
pub struct ConfigAnalysis {
pub file_path: PathBuf,
pub config_type: ConfigType,
pub line_count: usize,
pub complexity_score: u8,
pub issues: Vec<ConfigIssue>,
pub path_entries: Vec<PathEntry>,
pub performance_issues: Vec<PerformanceIssue>,
}
#[derive(Debug, Clone)]
pub struct ConfigIssue {
pub rule_id: String,
pub severity: Severity,
pub message: String,
pub line: usize,
pub column: usize,
pub suggestion: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Severity {
Error,
Warning,
Info,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PathEntry {
pub line: usize,
pub path: String,
pub is_duplicate: bool,
}
#[derive(Debug, Clone)]
pub struct PerformanceIssue {
pub line: usize,
pub command: String,
pub estimated_cost_ms: u32,
pub suggestion: String,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_type_from_path() {
assert_eq!(
ConfigType::from_path(&PathBuf::from("/home/user/.bashrc")),
ConfigType::Bashrc
);
assert_eq!(
ConfigType::from_path(&PathBuf::from("/home/user/.zshrc")),
ConfigType::Zshrc
);
assert_eq!(
ConfigType::from_path(&PathBuf::from("/home/user/.profile")),
ConfigType::Profile
);
}
#[test]
fn test_expected_shell() {
assert_eq!(ConfigType::Bashrc.expected_shell(), "bash");
assert_eq!(ConfigType::Zshrc.expected_shell(), "zsh");
assert_eq!(ConfigType::Profile.expected_shell(), "sh");
}
}