Skip to main content

codemod_core/transform/
mod.rs

1//! Transformation application, conflict detection, and rollback.
2//!
3//! This module orchestrates the process of applying pattern-based
4//! transformations to source files:
5//!
6//! - [`applier`]: Applies variable substitutions to produce new source text.
7//! - [`conflict`]: Detects overlapping or otherwise conflicting matches.
8//! - [`rollback`]: Saves and restores original file content for undo support.
9
10pub mod applier;
11pub mod conflict;
12pub mod rollback;
13
14pub use applier::TransformApplier;
15pub use conflict::ConflictResolver;
16pub use rollback::RollbackManager;
17
18use serde::{Deserialize, Serialize};
19use std::path::PathBuf;
20
21/// Result of a transformation applied to a single file.
22///
23/// Contains both the diff and the full original/new content so that the
24/// caller can preview changes, persist them, or roll them back.
25#[derive(Debug, Clone, Serialize, Deserialize)]
26pub struct TransformResult {
27    /// Path of the transformed file.
28    pub file_path: PathBuf,
29    /// Number of pattern matches found in the file.
30    pub match_count: usize,
31    /// Number of transformations successfully applied.
32    pub applied_count: usize,
33    /// Unified diff of the changes (suitable for display or patch files).
34    pub diff: String,
35    /// Original file content (for rollback).
36    pub original_content: String,
37    /// New file content after transformation.
38    pub new_content: String,
39}
40
41impl TransformResult {
42    /// Returns `true` if at least one transformation was applied.
43    pub fn has_changes(&self) -> bool {
44        self.applied_count > 0
45    }
46}