| Crates.io | noir-metrics |
| lib.rs | noir-metrics |
| version | 0.2.0 |
| created_at | 2025-11-25 08:17:26.04355+00 |
| updated_at | 2025-12-22 14:00:42.598912+00 |
| description | Source code metrics for Noir (Nargo) projects. |
| homepage | https://mutorium.com |
| repository | https://github.com/mutorium/noir-metrics |
| max_upload_size | |
| id | 1949415 |
| size | 68,504 |
Source code metrics for Noir projects.
noir-metrics scans a Nargo project (looks for Nargo.toml), walks all .nr files, and computes metrics that are useful for Noir developers, auditors, and tooling.
Status: This project is still under active development. The core API and JSON schema may evolve. Expect breaking changes before
1.0.0.
It is designed to be:
nargo metrics.Current metrics (per file and project-level totals):
total_lines, blank_lines, comment_lines, code_linestest_functions (functions annotated with #[test...])test_lines vs non_test_linesis_test_file flagfunctions, pub_functions, non_test_functionshas_main and files_with_maintodo_count (TODO/FIXME markers in comments or code)The report is exposed both as:
cargo install noir-metrics
This will install a noir-metrics binary into your Cargo bin directory.
Clone the repository and install from the local checkout:
git clone https://github.com/mutorium/noir-metrics.git
cd noir-metrics
cargo install --path .
Run noir-metrics in a Nargo project (directory containing Nargo.toml):
# Human-readable summary (default)
noir-metrics .
# JSON output to stdout
noir-metrics . --format json
# JSON output to a file
noir-metrics . --format json --output metrics.json
Available flags:
PROJECT_ROOT (positional): path to the Noir project (default: .)--format <human|json>: output format (default: human)--output <PATH>: write JSON output to the given file (requires --format json)-v, --verbose: print additional debug info to stderrBackwards compatibility:
--json is supported as a hidden alias for --format json (prefer --format json in scripts).Example (verbose JSON run):
noir-metrics . --format json --output metrics.json --verbose
When run with --format json, noir-metrics emits a JSON document of the form:
{
"tool": {
"name": "noir-metrics",
"version": "<VERSION>",
"schema_version": 1
},
"project_root": "path/to/project",
"totals": {
"files": 2,
"total_lines": 42,
"blank_lines": 5,
"comment_lines": 10,
"code_lines": 27,
"test_functions": 3,
"test_lines": 12,
"non_test_lines": 15,
"functions": 5,
"pub_functions": 1,
"non_test_functions": 2,
"todo_count": 1,
"files_with_main": 1,
"test_code_percentage": 44.44
},
"files": [
{
"path": "src/main.nr",
"is_test_file": false,
"total_lines": 20,
"blank_lines": 2,
"comment_lines": 3,
"code_lines": 15,
"test_functions": 1,
"test_lines": 5,
"non_test_lines": 10,
"functions": 2,
"pub_functions": 0,
"non_test_functions": 1,
"has_main": true,
"todo_count": 0
}
// ...
]
}
Schema version: The
tool.schema_versionfield is also available as the Rust constantJSON_SCHEMA_VERSIONand is incremented when breaking changes are made to the JSON layout. New fields may be added without bumping the schema version.
You can use noir-metrics as a library from other Rust crates.
Add it as a dependency:
[dependencies]
noir-metrics = "0.2"
Then call the library API:
use noir_metrics::{analyze_path, MetricsReport};
use std::path::Path;
fn run_metrics(root: &Path) -> anyhow::Result<MetricsReport> {
let report = analyze_path(root)?;
println!("Total code lines: {}", report.totals.code_lines);
Ok(report)
}
Core exported types:
analyze_path(&Path) -> Result<MetricsReport>MetricsReport (project_root, totals, per-file metrics)ProjectTotalsFileMetricsNoirProject (re-export of the internal Project type)JSON_SCHEMA_VERSIONThis is a line-based analyzer with Noir-aware heuristics:
// line comments and /* ... */ block comments are counted as comment lines.#[test], #[test(should_fail)], or other #[test(...)] forms are treated as tests.tests or test, or_test.nr.This tool does not parse Noir’s full AST (yet), so complex edge cases may not be classified perfectly. The goal is to provide useful, cheap metrics that are good enough for:
Planned / possible future work:
if, for/while loops, match--exclude target)nargo metrics subcommand built on this crateMIT
See LICENSE.