ryo-suggest 0.1.0

[experimental] Pattern-based suggestion engine for RYO
Documentation
//! Safety suggestions - Detect code safety improvement opportunities
//!
//! This module provides suggestions for improving code safety by detecting
//! potential panic points and suggesting safer alternatives.
//!
//! # Available Suggestions
//!
//! | Code | Name | Description |
//! |------|------|-------------|
//! | RS101 | `UnwrapToExpect` | Convert unwrap() to expect() with descriptive message |
//! | RS102 | `StringErrorType` | Detect string-based error types, suggest thiserror |
//!
//! # Architecture
//!
//! Safety suggestions analyze AST patterns to find potential panic points:
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────────┐
//! │  Safety Suggest Detection                                       │
//! │  ────────────────────────                                       │
//! │                                                                 │
//! │  Detection: AST traversal for method calls                      │
//! │    ├─ unwrap() on Option/Result                                 │
//! │    ├─ Filter: skip if function returns Option/Result (use ?)    │
//! │    └─ Context extraction for message generation                 │
//! │                                                                 │
//! │  Message Generation:                                            │
//! │    ├─ Variable context: "config should be Some"                 │
//! │    ├─ Field context: "self.data should be initialized"          │
//! │    └─ Method chain: "get_user() should return Some"             │
//! └─────────────────────────────────────────────────────────────────┘
//! ```

mod string_error_type;
mod unwrap_to_expect;

pub use string_error_type::StringErrorType;
pub use unwrap_to_expect::UnwrapToExpect;

use crate::{LintSeverity, OpportunityContext, OpportunityId, SuggestLocation, SuggestOpportunity};

/// Trait for safety-related suggestions
///
/// Provides common utilities for safety detection patterns.
pub trait SafetySuggest {
    /// Get the rule code (e.g., "RS101")
    fn code(&self) -> &'static str;

    /// Get the default severity for this safety issue
    fn default_severity(&self) -> LintSeverity {
        LintSeverity::Warning
    }

    /// Create a safety opportunity with standard context
    fn create_safety_opportunity(
        &self,
        id: OpportunityId,
        targets: Vec<ryo_analysis::SymbolId>,
        location: SuggestLocation,
        message: String,
        suggestion: String,
        confidence: f32,
    ) -> SuggestOpportunity {
        SuggestOpportunity::new(
            id,
            targets,
            location,
            message,
            confidence,
            OpportunityContext::Lint {
                code: self.code().to_string(),
                rule: self.code().to_string(),
                severity: self.default_severity(),
                suggestion: Some(suggestion),
                expected: None,
                actual: None,
            },
        )
    }
}