orlint/
lib.rs

1// Static analysis tool for Orbit UI framework files
2
3mod config;
4mod linter;
5pub mod parser;
6mod reporter;
7mod rules;
8
9use thiserror::Error;
10
11/// Export public API
12pub use config::{AnalyzerSettings, Config, RendererAnalysisConfig, ReporterConfig, RulesConfig};
13pub use linter::Linter;
14pub use reporter::{Issue, Reporter, Severity};
15pub use rules::{
16    ComponentNamingRule, NonEmptyTemplateRule, PropTypeRule, PublicFunctionRule,
17    RendererCompatibilityRule, Rule, StateVariableRule,
18};
19
20/// Version of the Orbit Analyzer
21pub const VERSION: &str = env!("CARGO_PKG_VERSION");
22
23/// Errors that can occur in the Orbit Analyzer
24#[derive(Debug, Error)]
25pub enum AnalyzerError {
26    #[error("Parser error: {0}")]
27    Parser(String),
28
29    #[error("Rule error: {0}")]
30    Rule(String),
31
32    #[error("IO error: {0}")]
33    Io(#[from] std::io::Error),
34
35    #[error("Configuration error: {0}")]
36    Config(String),
37}
38
39/// Result type for Orbit Analyzer operations
40pub type Result<T> = std::result::Result<T, AnalyzerError>;
41
42/// Analyze an .orbit file for issues
43pub fn analyze_file(file_path: &str) -> Result<Vec<reporter::Issue>> {
44    let content = std::fs::read_to_string(file_path)?;
45    let linter = Linter::new();
46    linter.lint(&content, file_path)
47}
48
49/// Analyze an .orbit file using a specific configuration
50pub fn analyze_file_with_config(file_path: &str, config: Config) -> Result<Vec<reporter::Issue>> {
51    let content = std::fs::read_to_string(file_path)?;
52    let linter = Linter::with_config(config);
53    linter.lint(&content, file_path)
54}
55
56/// Analyze multiple .orbit files
57pub fn analyze_files(file_paths: &[&str]) -> Result<Vec<reporter::Issue>> {
58    let linter = Linter::new();
59    let file_paths_vec: Vec<&str> = file_paths.to_vec();
60    linter.lint_files(&file_paths_vec)
61}
62
63/// Analyze multiple .orbit files using a specific configuration
64pub fn analyze_files_with_config(
65    file_paths: &[&str],
66    config: Config,
67) -> Result<Vec<reporter::Issue>> {
68    let linter = Linter::with_config(config);
69    let file_paths_vec: Vec<&str> = file_paths.to_vec();
70    linter.lint_files(&file_paths_vec)
71}