lint 0.1.3

A versatile linting tool with CLI, MCP, and library interfaces
Documentation
use crate::language_rules::LanguageRule;
use crate::output::LintMessage;
use regex::Regex;
use std::path::Path;
use std::sync::LazyLock;

#[derive(Debug, Clone)]
pub struct DartPrintRule;

static DART_PRINT_PATTERN: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"\bprint\s*\(").unwrap());

impl LanguageRule for DartPrintRule {
    fn name(&self) -> &str {
        "no-dart-print"
    }

    fn description(&self) -> &str {
        "Detects `print()` statements that should not be in production Dart code."
    }

    fn check(&self, content: &str, _file_path: &Path) -> Vec<LintMessage> {
        let mut messages = Vec::new();
        let pattern = &*DART_PRINT_PATTERN;

        for (line_num, line) in content.lines().enumerate() {
            if pattern.is_match(line) && !line.trim_start().starts_with("//") {
                messages.push(LintMessage::new(
                    line_num + 1,
                    line.find("print").unwrap_or(0),
                    self.default_severity(),
                    "print() call found".to_string(),
                    self.name().to_string(),
                    Some("Replace with debugPrint() or use the logging package: import 'dart:developer' as developer; developer.log('message')".to_string()),
                ));
            }
        }

        messages
    }

    fn supports_extension(&self, extension: &str) -> bool {
        extension == "dart"
    }
}