bito_lint_core/lib.rs
1//! Core library for bito-lint.
2//!
3//! This crate provides writing analysis functionality used by the
4//! `bito-lint` CLI and MCP server.
5//!
6//! # Modules
7//!
8//! - [`config`] — Configuration loading and management
9//! - [`error`] — Error types and result aliases
10//! - [`markdown`] — Markdown processing (strip to prose, extract headings)
11//! - [`tokens`] — Pluggable token counting (Claude / OpenAI backends)
12//! - [`readability`] — Flesch-Kincaid Grade Level scoring
13//! - [`completeness`] — Template section validation
14//! - [`grammar`] — Grammar checking and passive voice detection
15//! - [`analysis`] — Comprehensive writing analysis (18 features)
16//!
17//! # Quick Start
18//!
19//! ```no_run
20//! use bito_lint_core::tokens;
21//!
22//! let report = tokens::count_tokens("Hello, world!", Some(100), tokens::Backend::default()).unwrap();
23//! println!("Tokens: {}, over budget: {}", report.count, report.over_budget);
24//! ```
25#![deny(unsafe_code)]
26
27pub mod analysis;
28pub mod completeness;
29pub mod config;
30pub mod dictionaries;
31pub mod directives;
32pub mod error;
33pub mod grammar;
34pub mod lint;
35pub mod markdown;
36pub mod readability;
37pub mod rules;
38pub mod text;
39pub mod tokens;
40pub mod word_lists;
41
42pub use config::{Config, ConfigLoader, CustomEntry, Dialect, LogLevel};
43pub use error::{AnalysisError, AnalysisResult, ConfigError, ConfigResult};
44pub use tokens::Backend;
45
46/// Default maximum input size: 5 MiB.
47pub const DEFAULT_MAX_INPUT_BYTES: usize = 5_242_880;
48
49/// Validate that input text does not exceed the configured size limit.
50///
51/// Pass `None` for `max_bytes` to skip validation.
52pub const fn validate_input_size(text: &str, max_bytes: Option<usize>) -> AnalysisResult<()> {
53 if let Some(max) = max_bytes {
54 let size = text.len();
55 if size > max {
56 return Err(AnalysisError::InputTooLarge { size, max });
57 }
58 }
59 Ok(())
60}