ライブラリとしての利用
big-code-analysis は Rust ライブラリとして crates.io に公開されています。CLI(bca)と REST サーバー(bca-web)はどちらも同じ公開 API の薄いラッパーなので、それらにできることはすべて自分のクレートから直接行えます。
このセクションはタスク指向です。完全な型シグネチャとフィールドのドキュメントは docs.rs の rustdoc を参照してください。
ライブラリを組み込むべきとき
Use the library instead of shelling out to bca when you want any of the following:
- In-process analysis. Avoid spawning a subprocess per file when scoring thousands of files in a custom tool, IDE plugin, or static-analysis pipeline.
- インメモリソース。 生成された、前処理済みの、あるいはストリーミングされたソースを、先にディスクへ書き出すことなくスコアリングします。インメモリソースの分析を参照してください。
- 選択的な走査。
FuncSpaceツリーを独自に走査し、関数ごとのメトリクスを任意のタイミングで抽出します。FuncSpace 結果の走査を参照してください。 - Custom output. Skip the
bcaserializers (JSON / YAML / TOML / CBOR in the CLI, CSV / SARIF / Checkstyle in the library’soutputmodule) and emit your own format, such as a database row.
If you only want a Markdown quality report or a CI threshold gate, the bca CLI is faster to wire up.
Pages in this section
- Quick start: parse a string, get a
FuncSpace, print the cognitive complexity. - Analyzing in-memory source: feed source from a buffer rather than a file.
- Reusing an existing tree-sitter Tree: feed a caller-built
tree_sitter::Treeinto the metric walker. - Parse once, run metrics many times: hold a parsed
Astand run several metric subsets or custom walks against the same tree. - Walking the AST directly: count syntactic constructs, find nodes by kind, detect parse errors, or build a symbol table alongside the metrics walk.
- Selecting metrics: compute only the metrics you need with
MetricsOptions::with_only, including how dependent metrics pull in their inputs. - Walking
FuncSpaceresults: recurse into nested function, class and impl spaces. - Error handling: interpret
Result<FuncSpace, MetricsError>and turn errors into useful diagnostics. - Stability and versioning: identify what stays stable across the
2.xline.
API stability
このライブラリは 2.x 系にあり、明文化された安定性契約のもとで提供されています。公開 API の形状はパッチおよびマイナーバンプの間で安定に保たれ、破壊的変更は次のメジャーバンプまで保留されます。このセクションのすべての例は現在公開中のクレートに対してコンパイルでき、2.x の間は修正なしでコンパイルできることが期待されます。
Metric values may still drift across minor bumps when a grammar pin moves or a metric definition is fixed; see STABILITY.md § What is stable in value for the carve-out. Each drift is called out in the changelog entry that introduces it.