Skip to content

Commit ccea42d

Browse files
O6lvl4claude
andcommitted
Add README with full documentation
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dd3c0d8 commit ccea42d

1 file changed

Lines changed: 155 additions & 0 deletions

File tree

README.md

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
# codopsy
2+
3+
AST-level code quality analyzer for 19 languages. Uses [tree-sitter](https://tree-sitter.github.io/) to parse source code into ASTs and analyzes complexity, lint issues, and structural quality — without executing code.
4+
5+
## Supported Languages
6+
7+
| Language | Extensions | Lint Rules | Complexity |
8+
|----------|-----------|------------|------------|
9+
| TypeScript | `.ts` | 11 rules | CC + Cognitive |
10+
| TSX | `.tsx` | 11 rules | CC + Cognitive |
11+
| JavaScript | `.js` `.jsx` `.mjs` `.cjs` | 11 rules | CC + Cognitive |
12+
| Rust | `.rs` | 6 rules | CC + Cognitive |
13+
| Go | `.go` | threshold | CC + Cognitive |
14+
| Python | `.py` `.pyi` | threshold | CC + Cognitive |
15+
| C | `.c` `.h` | threshold | CC + Cognitive |
16+
| C++ | `.cpp` `.cc` `.cxx` `.hpp` `.hxx` | threshold | CC + Cognitive |
17+
| Java | `.java` | threshold | CC + Cognitive |
18+
| Ruby | `.rb` | threshold | CC + Cognitive |
19+
| C# | `.cs` | threshold | CC + Cognitive |
20+
| PHP | `.php` | threshold | CC + Cognitive |
21+
| Scala | `.scala` `.sc` | threshold | CC + Cognitive |
22+
| Haskell | `.hs` | threshold | CC + Cognitive |
23+
| Bash | `.sh` `.bash` `.zsh` | threshold | CC + Cognitive |
24+
| HTML | `.html` `.htm` | threshold | structure |
25+
| CSS | `.css` | threshold | structure |
26+
| JSON | `.json` | threshold | structure |
27+
| OCaml | `.ml` `.mli` | threshold | CC + Cognitive |
28+
29+
## Install
30+
31+
```bash
32+
cargo install --git https://github.com/O6lvl4/codopsy.git
33+
```
34+
35+
## Usage
36+
37+
```bash
38+
# Analyze a project
39+
codopsy analyze ./src
40+
41+
# Verbose output (per-file details)
42+
codopsy analyze ./src -v
43+
44+
# Output to stdout as JSON
45+
codopsy analyze ./src -o -
46+
47+
# Only analyze changed files (vs main branch)
48+
codopsy analyze ./src --diff main
49+
50+
# Show complexity hotspots (requires git)
51+
codopsy analyze ./src --hotspots
52+
53+
# Save baseline for regression tracking
54+
codopsy analyze ./src --save-baseline
55+
56+
# Fail CI if quality degrades
57+
codopsy analyze ./src --no-degradation --fail-on-warning
58+
59+
# Initialize config
60+
codopsy init
61+
```
62+
63+
## Quality Score
64+
65+
Projects are graded A–F based on three components:
66+
67+
| Component | Weight | What it measures |
68+
|-----------|--------|-----------------|
69+
| Complexity | 35% | Average & max cyclomatic complexity |
70+
| Issues | 40% | Lint violations per file |
71+
| Structure | 25% | File count & function distribution |
72+
73+
| Grade | Score |
74+
|-------|-------|
75+
| A | 90–100 |
76+
| B | 80–89 |
77+
| C | 70–79 |
78+
| D | 60–69 |
79+
| F | 0–59 |
80+
81+
## Configuration
82+
83+
Create `.codopsyrc.json` in your project root (or run `codopsy init`):
84+
85+
```json
86+
{
87+
"rules": {
88+
"no-console": "warning",
89+
"no-debugger": "error",
90+
"no-eval": "error",
91+
"max-lines": { "severity": "warning", "max": 300 },
92+
"max-depth": { "severity": "warning", "max": 4 },
93+
"max-params": { "severity": "warning", "max": 4 },
94+
"max-complexity": { "severity": "warning", "max": 10 },
95+
"max-cognitive-complexity": { "severity": "warning", "max": 15 },
96+
"no-println": false
97+
}
98+
}
99+
```
100+
101+
Rules can be set to `"warning"`, `"error"`, `"info"`, or `false` (disabled). Threshold rules accept `{ "severity": ..., "max": N }`.
102+
103+
Config is searched upward from the target directory to the home directory.
104+
105+
## Rules
106+
107+
### JS/TS Rules
108+
109+
| Rule | Default | Description |
110+
|------|---------|-------------|
111+
| `no-any` | warning | Disallow `any` type |
112+
| `no-console` | warning | Disallow `console.*` calls |
113+
| `no-var` | warning | Disallow `var` declarations |
114+
| `eqeqeq` | warning | Require `===`/`!==` over `==`/`!=` |
115+
| `no-empty-function` | warning | Disallow empty function bodies |
116+
| `no-nested-ternary` | warning | Disallow nested ternary expressions |
117+
| `no-debugger` | error | Disallow `debugger` statements |
118+
| `no-duplicate-case` | error | Disallow duplicate switch cases |
119+
| `no-self-assign` | warning | Disallow self-assignment |
120+
| `no-eval` | error | Disallow `eval()` |
121+
| `no-unreachable` | error | Detect unreachable code after return/throw |
122+
123+
### Rust Rules
124+
125+
| Rule | Default | Description |
126+
|------|---------|-------------|
127+
| `no-unsafe` | warning | Disallow `unsafe` blocks |
128+
| `no-unwrap` | warning | Disallow `.unwrap()` |
129+
| `no-dbg` | warning | Disallow `dbg!()` macro |
130+
| `no-todo` | warning | Disallow `todo!()`/`unimplemented!()` |
131+
| `no-println` | info | Disallow `println!()`/`print!()` etc. |
132+
| `no-empty-function` | warning | Disallow empty function bodies |
133+
134+
### Threshold Rules (all languages)
135+
136+
| Rule | Default | Description |
137+
|------|---------|-------------|
138+
| `max-lines` | 300 | Maximum lines per file |
139+
| `max-depth` | 4 | Maximum nesting depth |
140+
| `max-params` | 4 | Maximum function parameters |
141+
| `max-complexity` | 10 | Maximum cyclomatic complexity per function |
142+
| `max-cognitive-complexity` | 15 | Maximum cognitive complexity per function |
143+
144+
## How It Works
145+
146+
1. **Parse**: tree-sitter converts source code into a language-agnostic AST
147+
2. **Analyze**: Walk the AST to compute cyclomatic/cognitive complexity and detect lint violations
148+
3. **Score**: Weighted scoring across complexity, issues, and structure
149+
4. **Report**: JSON output with per-file and per-function details
150+
151+
All analysis is static — no code execution required. Files are analyzed in parallel via [rayon](https://github.com/rayon-rs/rayon).
152+
153+
## License
154+
155+
MIT

0 commit comments

Comments
 (0)