#![cfg_attr(coverage_nightly, coverage(off))]
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::path::Path;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum Severity {
Critical, High,
Medium,
Low,
}
impl Severity {
#[provable_contracts_macros::contract("pmat-core.yaml", equation = "check_compliance")]
pub fn as_str(&self) -> &'static str {
match self {
Severity::Critical => "CRITICAL",
Severity::High => "HIGH",
Severity::Medium => "MEDIUM",
Severity::Low => "LOW",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DefectInstance {
pub file: String,
pub line: usize,
pub column: usize,
pub code_snippet: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DefectPattern {
pub id: String,
pub name: String,
pub severity: Severity,
pub fix_recommendation: String,
pub bad_example: String,
pub good_example: String,
pub evidence_description: String,
pub evidence_url: Option<String>,
pub instances: Vec<DefectInstance>,
}
pub struct RustDefectDetector {
unwrap_regex: Regex,
}
pub struct LuaDefectDetector {
global_assign_re: Regex,
nil_chain_re: Regex,
unchecked_pcall_re: Regex,
dangerous_api_re: Regex,
}
include!("defect_detector_rust.rs");
include!("defect_detector_lua.rs");
include!("defect_detector_tests.rs");