Skip to main content

react_auditor/
cli.rs

1use clap::{Parser, Subcommand};
2
3#[derive(Parser, Debug)]
4#[command(
5    name = "react-auditor",
6    version,
7    about = "A blazing-fast Rust CLI to scan JS/TS/React code for best practices, quality, and security issues",
8    long_about = "react-auditor — Scan JS/TS/React Code for Best Practices
9
10A blazing-fast Rust CLI powered by oxc to lint your React codebase for
11quality, correctness, security, performance, and accessibility issues.
12
13Categories (71 rules total):
14  quality        Code quality & clean code (13 rules)
15  react          React best practices & hooks (19 rules)
16  typescript     TypeScript strictness (9 rules)
17  security       Security vulnerabilities (7 rules)
18  nextjs         Next.js best practices (5 rules)
19  performance    Performance anti-patterns (5 rules)
20  accessibility  Accessibility violations (11 rules)
21  testing        Test quality & correctness (2 rules)
22
23Presets:
24  recommended    Default severity for all rules
25  strict         Bump many rules to Error
26  nextjs         Focus on Next.js + React rules
27  all            Maximum severity for all rules
28
29Integrated with lint-staged and husky for pre-commit checks.
30
31Examples:
32  react-auditor                              Scan src/**/*.{js,jsx,ts,tsx}
33  react-auditor src/ --format json            Scan src/ output as JSON
34  react-auditor --rules react,typescript      Only React & TS rules
35  react-auditor --preset strict               Use strict preset
36  react-auditor --ignore node_modules,dist    Skip node_modules and dist
37  react-auditor --log audit.json              Write JSON log file
38  react-auditor --max-warnings 10             Fail on >10 warnings
39  react-auditor --fail-on warning             Fail on any violation
40  react-auditor --fix                         Auto-fix where supported
41  react-auditor init                          Install pre-commit hook
42
43Configuration: .rauditrc.toml, .rauditrc.json, or package.json#reactAuditor"
44)]
45pub struct Cli {
46    /// File paths or glob patterns to scan (default: src/**/*.{js,jsx,ts,tsx})
47    pub files: Vec<String>,
48
49    /// Path to config file (.rauditrc.toml, .rauditrc.json, package.json)
50    #[arg(short = 'c', long = "config")]
51    pub config: Option<String>,
52
53    /// Comma-separated rule categories to enable: quality, react, typescript, security, nextjs, performance, accessibility, testing
54    #[arg(short = 'r', long = "rules")]
55    pub rules: Option<String>,
56
57    /// Configuration preset: recommended (default), strict, nextjs, all
58    #[arg(long = "preset", default_value = "recommended")]
59    pub preset: String,
60
61    /// Fail on severity level: error, warning (exit code 1 if any violations at or above this level)
62    #[arg(long = "fail-on", default_value = "error")]
63    pub fail_on: String,
64
65    /// Path to output JSON log file
66    #[arg(short = 'l', long = "log")]
67    pub log: Option<String>,
68
69    /// Output format: stylish (default), json, compact
70    #[arg(short = 'f', long = "format", default_value = "stylish")]
71    pub format: String,
72
73    /// Max warnings before exiting with code 1
74    #[arg(short = 'w', long = "max-warnings")]
75    pub max_warnings: Option<u32>,
76
77    /// Only output errors (suppress warnings)
78    #[arg(short = 'q', long = "quiet")]
79    pub quiet: bool,
80
81    /// Comma-separated glob patterns to ignore (e.g. node_modules,dist,build)
82    #[arg(long = "ignore", default_value = "")]
83    pub ignore: String,
84
85    /// Auto-fix violations where supported (currently: no-var, no-console, no-empty-blocks, prefer-fragments, prefer-function-components)
86    #[arg(long = "fix")]
87    pub fix: bool,
88
89    /// Disable incremental caching (re-scan all files)
90    #[arg(long = "no-cache")]
91    pub no_cache: bool,
92
93    /// Watch mode: re-scan on file changes
94    #[arg(short = 'W', long = "watch")]
95    pub watch: bool,
96
97    /// Generate rule documentation in docs/rules/
98    #[arg(long = "docs")]
99    pub docs: bool,
100
101    #[command(subcommand)]
102    pub command: Option<Commands>,
103}
104
105#[derive(Subcommand, Debug)]
106pub enum Commands {
107    /// Install a pre-commit git hook that runs react-auditor on staged files
108    Init,
109}