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