Skip to main content

pedant_core/
lib.rs

1//! Analysis engine for pedant: IR extraction, capability detection, and style checks.
2//!
3//! `pedant-core` provides the core analysis pipeline without CLI dependencies.
4//! It presents two surfaces over one module tree, selected by feature.
5//!
6//! The **substrate** is present in every configuration. It answers factual
7//! questions about source text: [`ir`] extracts facts, [`capabilities`] resolves
8//! them to capabilities, [`resolution`] models the Cargo project those files
9//! belong to, and [`hash`] and [`pattern`] support them. No substrate entry
10//! point accepts policy input.
11//!
12//! The **judgment** surface sits behind the `checks` feature, which is on by
13//! default. It answers acceptability questions and owns every type whose shape
14//! is determined by an opinion: the check catalog, the gate rules engine, check
15//! configuration, violations, and the orchestrating `lint` entry points. A
16//! consumer that wants facts without opinions takes `default-features = false`.
17//!
18//! `semantic` is a third, orthogonal axis. It combines with either surface, and
19//! enabling `checks` does not enable it.
20//!
21//! # Quick start
22//!
23//! ```
24//! use pedant_core::capabilities::detect_capabilities;
25//! use pedant_core::ir::extract;
26//! use pedant_types::Capability;
27//!
28//! let syntax = syn::parse_file("use std::fs;").expect("source parses");
29//! let ir = extract("example.rs", &syntax, None);
30//! let profile = detect_capabilities(&ir, None);
31//!
32//! assert_eq!(profile.findings[0].capability, Capability::FileRead);
33//! ```
34
35/// Violations + capabilities produced by a single analysis run.
36#[cfg(feature = "checks")]
37pub mod analysis_result;
38/// Path-based capability detection over extracted IR facts.
39pub mod capabilities;
40/// `.pedant.toml` schema, loading, and per-path override resolution.
41#[cfg(feature = "checks")]
42pub mod check_config;
43/// Check catalog: metadata, rationale, and the `ViolationType` enum.
44#[cfg(feature = "checks")]
45pub mod checks;
46/// Security gate rules that fire on suspicious capability combinations.
47#[cfg(feature = "checks")]
48pub mod gate;
49/// BFS and pairwise-edge helpers for type-relationship graphs.
50pub(crate) mod graph;
51/// SHA-256 hashing of source contents for attestation.
52pub mod hash;
53/// Intermediate representation extracted from the AST in one pass.
54pub mod ir;
55/// JSON serialization for machine-readable violation output.
56#[cfg(feature = "checks")]
57pub mod json_format;
58/// High-level analysis entry points and error types.
59///
60/// ```
61/// use pedant_core::{lint_str, Config};
62///
63/// let config = Config::default();
64/// let result = lint_str("fn f() { if true { if false {} } }", &config).unwrap();
65/// assert!(!result.violations.is_empty());
66/// ```
67#[cfg(feature = "checks")]
68pub mod lint;
69/// Observation hooks the proof feature reads; inert in ordinary builds.
70pub(crate) mod observe;
71/// Glob and wildcard matching for AST node text and file paths.
72pub mod pattern;
73/// Whole-workspace structural checks over the file tree and Cargo metadata.
74#[cfg(feature = "checks")]
75pub mod project;
76/// Language-scoped project and symbol-resolution models.
77pub mod resolution;
78/// Style checks that consume IR facts and produce violations.
79#[cfg(feature = "checks")]
80pub mod style;
81/// The `Violation` type, display formatting, and check rationale.
82#[cfg(feature = "checks")]
83pub mod violation;
84
85#[cfg(feature = "checks")]
86pub use analysis_result::AnalysisResult;
87#[cfg(feature = "checks")]
88pub use check_config::{
89    CheckConfig as Config, ConfigFile, GateConfig, GateRuleOverride, NamingCheck, PatternCheck,
90    PatternOverride,
91};
92#[cfg(feature = "checks")]
93pub use checks::{ALL_CHECKS, CheckInfo};
94#[cfg(feature = "checks")]
95pub use gate::{
96    GateInputSummary, GateRuleInfo, GateSeverity, GateVerdict, all_gate_rules, evaluate_gate_rules,
97};
98#[cfg(feature = "checks")]
99pub use lint::{
100    LintError, analyze, analyze_build_script, analyze_build_script_with_shape,
101    analyze_with_build_script, analyze_with_shape, determine_analysis_tier, discover_build_script,
102    discover_crate_root, discover_workspace_root, lint_file, lint_str,
103};
104#[cfg(feature = "checks")]
105pub use violation::{CheckRationale, Violation, ViolationType, lookup_rationale};
106
107/// Alias for `syn::Error`, used by consumers that parse source themselves.
108pub use syn::Error as ParseError;
109
110#[cfg(feature = "semantic")]
111pub use ir::semantic::FunctionAnalysisSummary;
112pub use ir::semantic::{SemanticContext, SemanticFileAnalysis};