Skip to content

Analyze CLI (tools/analyze)

AST-based deep analysis CLI (@booking/tools-analyze) that scans source files with @ast-grep/napi and reports structural findings across 5 domains.

Overview

The analyze tool performs in-process AST analysis to detect structural code issues. Each finding maps to a review workflow, enabling automated quality gates in CI pipelines and pre-PR checks.

Tech Stack

LayerTechnologyVersion
RuntimeBun>= 1.3.14
LanguageTypeScript^7.0.2
AST Engine@ast-grep/napi^0.44.1
ArchitectureClean Architecture
Bundlingbunup^0.16.32
LintingBiome^2.5.6
Type Checkingtsc^7.0.2
TestingVitest^4.1.10

Analysis Domains

DomainRulesReview Workflow
Structureno-default-export, no-barrel-in-deep/review-architecture
Complexitydeep-nesting, long-function-body/review-refactor
Patternsno-console-log, no-any, no-ts-ignore, no-todo/review-code-quality
Dependenciesno-cross-domain-import/review-architecture
Dead Codeunused-private-function/check-unused-files

Architecture

tools/analyze/src/
├── index.ts               # Library entry point
├── domain/                 # Pure analyzer definitions + types
│   └── analyzers/          # Analyzer rules (5 domains)
├── application/            # Report builder, scorer
├── adapters/               # @ast-grep/napi wrapper, file discovery
└── presentation/           # CLI entry, args, format, help

Key Scripts

bash
# Run analysis (table output, default)
moon run tools-analyze:analyze

# JSON output for automation
moon run tools-analyze:analyze-json

# Markdown output
moon run tools-analyze:analyze-markdown

# Build
moon run tools-analyze:build

# Quality
moon run tools-analyze:lint
moon run tools-analyze:typecheck
moon run tools-analyze:verify

CLI Usage

bash
# Table format (default)
bun run analyze

# JSON format
bun run analyze:json

# Markdown format
bun run analyze:markdown

# Filter by domain and severity
bun run analyze -- --domain Complexity --severity High

# Write to file
bun run analyze -- --format json -o analysis.json

CLI Options

OptionDescription
--format <json|table|markdown>Output format (default: table)
--output <path>, -oWrite report to file instead of stdout
--domain <name>Filter by analyzer domain
--severity <Critical|High|Medium|Low>Filter by severity
--verbose, -vShow full evidence snippets
--help, -hShow help

Released under the MIT License.