ryo-mutations 0.1.0

[experimental] Code transformation primitives for Rust source code
Documentation
//! OrganizeImportsMutation: Sort and group use statements idiomatically
//!
//! Groups:
//! 1. `std` / `core` / `alloc` (standard library)
//! 2. External crates
//! 3. `crate::` / `super::` / `self::` (local)
//!
//! Within each group, sorted alphabetically.

use crate::Mutation;

/// Organize and sort use statements
#[derive(Debug, Clone, Default)]
pub struct OrganizeImportsMutation {
    /// Remove duplicate imports
    pub deduplicate: bool,
    /// Merge imports with same prefix into groups
    pub merge_groups: bool,
}

impl OrganizeImportsMutation {
    pub fn new() -> Self {
        Self {
            deduplicate: true,
            merge_groups: true,
        }
    }

    pub fn with_deduplicate(mut self, deduplicate: bool) -> Self {
        self.deduplicate = deduplicate;
        self
    }

    pub fn with_merge_groups(mut self, merge: bool) -> Self {
        self.merge_groups = merge;
        self
    }
}

impl Mutation for OrganizeImportsMutation {
    fn describe(&self) -> String {
        "Organize imports: sort and group use statements".to_string()
    }

    fn mutation_type(&self) -> &'static str {
        "OrganizeImports"
    }

    fn box_clone(&self) -> Box<dyn Mutation> {
        Box::new(self.clone())
    }
}