cargo_korox/lib.rs
1//! # cargo-korox
2//!
3//! A lightweight, **Rust-native** developer quality toolkit for cleaner, safer, and more maintainable Rust code.
4//! Runs locally with no cloud, no AI required.
5//!
6//! ## Overview
7//!
8//! `cargo-korox` unifies project-level diagnostics into one developer-oriented command:
9//!
10//! ```bash
11//! cargo install cargo-korox
12//! cargo korox check
13//! ```
14//!
15//! Instead of running multiple commands:
16//! ```bash
17//! cargo check
18//! cargo clippy
19//! cargo fmt --check
20//! ```
21//!
22//! ## Features
23//!
24//! - **Local-first** — Your code never leaves your machine
25//! - **Zero dependencies** — Native Rust binary, no Python/Node/Docker/GPU
26//! - **Rust-native** — Understands ownership, borrowing, lifetimes, async, Tokio, unsafe
27//! - **Actionable diagnostics** — Explains *what*, *why*, *where*, and *how to fix*
28//! - **AI optional** — Core works without LLMs; AI layer is opt-in
29//! - **CI/CD ready** — `--strict` for CI, `--json` for editors/automation
30//! - **Git-aware** — `--changed` scans only modified files
31//!
32//! ## Rules
33//!
34//! | Rule | Severity | Description |
35//! |------|----------|-------------|
36//! | `unnecessary-clone` | Warning | Detects avoidable `.clone()` calls |
37//! | `suspicious-unwrap` | Warning | Detects `.unwrap()`/`.expect()` that can panic |
38//! | `unused-variable` | Suggestion | Detects unused `let` bindings |
39//! | `unnecessary-allocation` | Warning | Detects `Vec::new()`/`String::new()` filled in loops |
40//! | `inefficient-loop` | Warning | Detects indexing, cloning in loops |
41//! | `error-handling` | Error/Warning | Detects `panic!`, `todo!`, `unreachable!`, `.expect()` |
42//! | `unnecessary-conversion` | Suggestion | Detects `to_owned()` on literals, `as` casts |
43//! | `collection-in-loop` | Warning | Detects `Vec`/`HashMap`/`String` created inside loops |
44//! | `inefficient-string-concat` | Warning | Detects multiple `+` concatenations |
45//! | `redundant-clone` | Warning | Detects double clone, clone + to_string |
46//!
47//! ## Configuration
48//!
49//! Create `korox.toml` in your project root:
50//!
51//! ```toml
52//! [tool.korox]
53//! strict = false
54//!
55//! [tool.korox.rules]
56//! unnecessary_clone = "warn"
57//! suspicious_unwrap = "warn"
58//! unused_variable = "suggestion"
59//! ```
60//!
61//! Severity levels: `deny` • `warn` • `suggestion` • `allow`
62//!
63//! ## Usage as Library
64//!
65//! You can also use cargo-korox as a library in your own tools:
66//!
67//! ```rust
68//! use cargo_korox::{run_check, Diagnostic};
69//! use std::path::PathBuf;
70//!
71//! let diagnostics = run_check(&PathBuf::from("."), false, false, false)?;
72//! for diag in diagnostics {
73//! println!("{}:{} {}", diag.file, diag.line, diag.message);
74//! }
75//! ```
76//!
77//! ## License
78//!
79//! Licensed under either of:
80//! - Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE))
81//! - MIT license ([LICENSE-MIT](LICENSE-MIT))
82
83pub mod cli;
84pub mod commands;
85pub mod config;
86pub mod diagnostics;
87pub mod rules;
88pub mod scanner;
89
90pub use commands::run_check;
91pub use diagnostics::Diagnostic;
92pub use rules::{Rule, RuleContext};
93pub use scanner::scan_project;
94
95#[cfg(test)]
96mod tests {
97 use super::*;
98 use std::path::PathBuf;
99
100 #[test]
101 fn test_scan_project() {
102 let files = scan_project(&PathBuf::from(".")).unwrap();
103 assert!(!files.is_empty());
104 }
105}