Skip to main content

pedant_core/project/
context.rs

1use std::path::Path;
2
3use crate::check_config::CheckConfig;
4use crate::violation::Violation;
5
6use super::cargo_meta::CargoMetadata;
7use super::shape::FileShape;
8use super::{feature_boundary, module_layout, type_footprint};
9
10/// Inputs for whole-workspace structural checks. Unlike per-file style checks,
11/// these examine the source tree, Cargo metadata, and the per-file shape
12/// projections rather than a single AST.
13pub struct ProjectContext<'a> {
14    /// Paths of the Rust source files under analysis, as passed on the CLI.
15    pub rust_files: &'a [String],
16    /// Workspace root directory, for resolving path-relative config rules.
17    pub workspace_root: &'a Path,
18    /// Parsed `cargo metadata`, when the feature-boundary check needs it.
19    pub metadata: Option<&'a CargoMetadata>,
20    /// One [`FileShape`] per analyzed Rust file, in analysis order.
21    pub file_shapes: &'a [FileShape],
22}
23
24/// Run every enabled project-level check, appending to `violations`.
25///
26/// `violations` carries the per-file findings collected so far, because a check
27/// with a whole-crate view may supersede a per-file finding that saw only a
28/// slice of the same problem.
29pub fn check_project(
30    ctx: &ProjectContext<'_>,
31    config: &CheckConfig,
32    violations: &mut Vec<Violation>,
33) {
34    module_layout::check_conflicting_module_root(ctx, config, violations);
35    module_layout::check_flat_module_family(ctx, config, violations);
36    feature_boundary::check_feature_boundary(ctx, config, violations);
37    type_footprint::check_type_footprint(ctx, config, violations);
38}