mod builtin;
mod loader;
mod runner;
mod sources;
pub use builtin::BUILTIN_RULES;
pub use loader::{RuleOverride, RulesConfig, load_all_rules, parse_rule_content};
pub use runner::{DebugFlags, Finding, apply_fixes, evaluate_predicates, run_rules};
pub use sources::{
EnvSource, GitSource, GoSource, PathSource, PythonSource, RuleSource, RustSource,
SourceContext, SourceRegistry, TypeScriptSource, builtin_registry,
};
use glob::Pattern;
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Severity {
Error,
#[default]
Warning,
Info,
}
impl std::fmt::Display for Severity {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Severity::Error => write!(f, "error"),
Severity::Warning => write!(f, "warning"),
Severity::Info => write!(f, "info"),
}
}
}
impl std::str::FromStr for Severity {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"error" => Ok(Severity::Error),
"warning" | "warn" => Ok(Severity::Warning),
"info" | "note" => Ok(Severity::Info),
_ => Err(format!("unknown severity: {}", s)),
}
}
}
#[derive(Debug)]
pub struct Rule {
pub id: String,
pub query_str: String,
pub severity: Severity,
pub message: String,
pub allow: Vec<Pattern>,
pub source_path: PathBuf,
pub languages: Vec<String>,
pub enabled: bool,
pub builtin: bool,
pub requires: HashMap<String, String>,
pub fix: Option<String>,
}
pub struct BuiltinRule {
pub id: &'static str,
pub content: &'static str,
}