| Crates.io | lynx_eye |
| lib.rs | lynx_eye |
| version | 0.0.3 |
| created_at | 2025-12-21 23:22:26.746593+00 |
| updated_at | 2025-12-23 14:32:26.764214+00 |
| description | A code complexity analyzer for JavaScript, TypeScript, and Rust using tree-sitter. Calculates NLOC, CCN, token count, and complexity scores. |
| homepage | https://github.com/yzzting/LynxEye |
| repository | https://github.com/yzzting/LynxEye |
| max_upload_size | |
| id | 1998739 |
| size | 101,855 |
Lynx Eye is a code analysis tool similar to Lizard, built with Rust and tree-sitter. It analyzes code metrics for JavaScript, TypeScript, and Rust, focusing on function-level static analysis to help identify complex or oversized functions that may need refactoring.
--trace modegit clone https://github.com/yzzting/LynxEye.git
cd LynxEye
cargo build --release
The release binary will be available at target/release/lynx_eye.
cargo install lynx_eye
# Show help
lynx_eye --help
# Show version
lynx_eye --version
# Analyze a single file
lynx_eye demo/test.js
# Analyze multiple files
lynx_eye demo/test.js demo/test.ts src/lib.rs
# Analyze an entire directory (non-recursive)
lynx_eye demo/
# Analyze directory recursively (includes subdirectories)
lynx_eye --recursive demo/
lynx_eye -r src/
Table Format (Default)
lynx_eye demo/test.js
Output:
+------+-----+-------+-------+-------+----------------+------+---------+
| NLOC | CCN | Token | Param | Score | Function | Line | File |
+======================================================================+
| 7 | 2 | 30 | 1 | 24.4 | calculateTotal | 1 | test.js |
|------+-----+-------+-------+-------+----------------+------+---------|
| 3 | 1 | 13 | 2 | 17.2 | add | 14 | test.js |
+------+-----+-------+-------+-------+----------------+------+---------+
JSON Format
lynx_eye --format json demo/test.js
CSV Format
lynx_eye --format csv demo/test.js
# Show only functions with complexity score >= 40
lynx_eye --min-score 40 demo/
# Show only highly complex functions (CCN >= 10)
lynx_eye --min-ccn 10 demo/
# Show only large functions (NLOC >= 20)
lynx_eye --min-nloc 20 demo/
# Show functions with many parameters (>= 5)
lynx_eye --min-params 5 demo/
# Combine multiple filters
lynx_eye --min-score 50 --min-ccn 5 --min-nloc 20 demo/
# Save JSON output
lynx_eye --format json --output analysis.json demo/
# Save CSV output
lynx_eye --format csv --output analysis.csv demo/
Dynamic analysis traces code execution at runtime to measure which lines are actually executed.
# Analyze with entry point
lynx_eye --trace src/ --entry main.js
# Analyze with test command
lynx_eye --trace src/ --test-cmd "npm test"
# Analyze single file
lynx_eye --trace demo/trace_test.js --entry trace_test.js
+------+-----+-------+-------+-------+----------+----------------+------+---------------+
| NLOC | CCN | Token | Param | Score | LiveRate | Function | Line | File |
+=======================================================================================+
| 3 | 1 | 14 | 2 | 18.0 | 100% | add | 3 | trace_test.js |
|------+-----+-------+-------+-------+----------+----------------+------+---------------|
| 10 | 3 | 64 | 3 | 36.0 | 60% | calculate | 11 | trace_test.js |
|------+-----+-------+-------+-------+----------+----------------+------+---------------|
| 4 | 1 | 19 | 0 | 19.2 | 0% | unusedFunction | 23 | trace_test.js |
+------+-----+-------+-------+-------+----------+----------------+------+---------------+
Dead Code Report:
=================
calculate (trace_test.js:11-21)
LiveRate: 60.0% (3/5 lines executed)
- Lines 18-19: Never executed
unusedFunction (trace_test.js:23-27)
LiveRate: 0.0% (0/2 lines executed)
- Lines 25-26: Never executed
Dynamic analysis supports cross-file tracing:
# Analyze entire directory with entry point
lynx_eye --trace src/ --entry main.js
This will:
src/main.js| LiveRate | Meaning |
|---|---|
| 100% | All code in the function was executed |
| 70-99% | Most code executed, some branches not taken |
| 50-69% | Significant unused branches |
| 1-49% | Most code never executed |
| 0% | Function was never called |
| Language | Extensions | Static Analysis | Dynamic Analysis |
|---|---|---|---|
| JavaScript | .js, .mjs, .cjs |
✅ | ✅ |
| TypeScript | .ts, .tsx, .mts |
✅ | 🔜 Planned |
| Rust | .rs |
✅ | 🔜 Planned |
The number of lines containing actual code, excluding empty lines and comments.
function example(param) { // Not counted (comment)
let result = param; // NLOC: 1 ✅
// This is a comment // Not counted
return result; // NLOC: 1 ✅
} // NLOC: 1 ✅
// Total NLOC: 3
Threshold: Functions with NLOC > 30 are considered large.
The number of independent paths through the code.
if, for, while, do, switch case, ? :, &&, ||, catchfunction example(value) { // Base: 1
if (value > 10) { // +1 = 2
return value * 2;
} else if (value < 5) { // +1 = 3
return value / 2;
}
return value + 1; // Total CCN: 3
}
Threshold: CCN > 15 indicates highly complex code.
A composite score combining multiple metrics:
Score = 0.5 × CCN_norm + 0.3 × NLOC_norm + 0.2 × Density_norm
| Score | Interpretation |
|---|---|
| 0-30 | Simple function ✅ |
| 30-60 | Moderate complexity ⚠️ |
| 60-100 | High complexity ❌ |
Percentage of code lines actually executed during runtime.
LiveRate = (Executed Lines / Instrumented Lines) × 100%
| LiveRate | Interpretation |
|---|---|
| 90-100% | Most code is actively used ✅ |
| 70-90% | Some unused branches (normal) |
| 50-70% | Significant dead code ⚠️ |
| < 50% | Major dead code problem ❌ |
# Build the project
cargo build
# Run in debug mode
cargo run
# Build optimized release version
cargo build --release
# Run all tests
cargo test
# Run a specific test
cargo test test_function_name
# Quick check without building
cargo check
# Run linter
cargo clippy
# Format code
cargo fmt
# Clean build artifacts
cargo clean
Lynx Eye uses tree-sitter to parse source code into a Concrete Syntax Tree (CST), then:
Static Analysis:
Dynamic Analysis (JS only):
__lynx.hit() callssrc/
├── analysis.rs # Static analysis logic
├── parser.rs # Tree-sitter parsing
├── languages/ # Language-specific configs
│ ├── mod.rs
│ ├── javascript.rs
│ └── rust.rs
├── trace/ # Dynamic analysis
│ ├── mod.rs
│ ├── instrumenter.rs
│ ├── executor.rs
│ ├── reporter.rs
│ └── runtime/
│ └── js_runtime.js
├── lib.rs
└── main.rs
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.