#![warn(missing_docs)]
pub mod cli;
pub mod discover;
pub mod error;
pub mod format;
pub mod io;
pub mod lint;
pub mod migrate;
pub mod parse;
pub mod report;
pub mod schema;
pub mod spec;
pub mod walk;
pub use error::Error;
pub use format::{RuleFormat, RuleFormatArg};
pub use lint::{exceeds_threshold, lint_directory, lint_string};
pub use migrate::{
InputRule, MigrateOptions, MigrateResult, MigrateSummary, MigrateWarning,
build_inputs_from_dirs, migrate_paths, migrate_string,
};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Severity {
Warn,
Error,
}
impl Severity {
pub fn meets_threshold(self, threshold: Self) -> bool {
self >= threshold
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Violation {
pub severity: Severity,
pub field: String,
pub message: String,
pub spec_ref: &'static str,
}
#[derive(Debug, Clone)]
pub struct LintOptions {
pub severity_threshold: Severity,
pub filename_hint: Option<String>,
}
impl Default for LintOptions {
fn default() -> Self {
Self {
severity_threshold: Severity::Error,
filename_hint: None,
}
}
}
#[derive(Debug, Clone)]
pub struct LintReport {
pub violations: Vec<Violation>,
pub valid: bool,
}
#[derive(Debug, Clone)]
pub struct FileLintResult {
pub path: PathBuf,
pub report: LintReport,
}
#[derive(Debug, Clone, Deserialize)]
pub struct SpecIndex {
pub repository: String,
pub commit: String,
pub files: Vec<SpecIndexEntry>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct SpecIndexEntry {
pub vendored: String,
pub upstream: String,
}
pub fn load_spec_index() -> Result<SpecIndex, Error> {
serde_saphyr::from_str(spec::EMBEDDED_INDEX).map_err(|e| Error::Yaml(e.to_string()))
}