1mod config;
4mod linter;
5pub mod parser;
6mod reporter;
7mod rules;
8
9use thiserror::Error;
10
11pub 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
20pub const VERSION: &str = env!("CARGO_PKG_VERSION");
22
23#[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
39pub type Result<T> = std::result::Result<T, AnalyzerError>;
41
42pub 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
49pub 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
56pub 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
63pub 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}