Skip to content

moss analyze

Analyze codebase quality: health, complexity, security, duplicates, hotspots.

Subcommands

SubcommandDescription
(none)Default: health analysis
healthFile counts, complexity stats, large file warnings
overviewComprehensive project summary with grade
complexityCyclomatic complexity analysis
lengthFunction length analysis
securitySecurity vulnerability patterns
docsDocumentation coverage
filesLongest files in codebase
hotspotsGit history hotspots (frequently changed files)
duplicate-functionsDetect code clones
duplicate-typesDetect similar type definitions
traceTrace value provenance for a symbol
callersShow what calls a symbol
calleesShow what a symbol calls
lintRun configured linters
check-refsCheck documentation for broken links
stale-docsFind docs with stale code references
check-examplesCheck example references in docs
allRun all analysis passes with overall grade

Examples

bash
# Quick health check
moss analyze

# Comprehensive overview
moss analyze overview

# Find complex functions
moss analyze complexity --threshold 15

# Security scan
moss analyze security

# Find code duplicates
moss analyze duplicate-functions

# Git hotspots (frequently changed files)
moss analyze hotspots

# Trace a symbol's data flow
moss analyze trace parse_config

# Call graph
moss analyze callers handle_request
moss analyze callees main

Options

Global

  • -r, --root <PATH> - Root directory
  • --json - Output as JSON
  • --jq <EXPR> - Filter JSON with jq
  • --pretty - Human-friendly output
  • --compact - Compact output without colors
  • --exclude <PATTERN> - Exclude paths
  • --only <PATTERN> - Include only paths
  • --diff [<BASE>] - Analyze only files changed since base ref (default: origin's default branch)

Subcommand-specific

complexity:

  • -t, --threshold <N> - Only show functions above threshold
  • --kind <TYPE> - Filter by: function, method

files / hotspots:

  • --allow <PATTERN> - Add pattern to allow file
  • --reason <TEXT> - Reason for allowing (with --allow)
  • -n, --limit <N> - Number of results to show

duplicate-functions:

  • --elide-identifiers - Ignore identifier names when comparing (default: true)
  • --elide-literals - Ignore literal values when comparing
  • --show-source - Show source code for duplicates
  • --min-lines <N> - Minimum function lines to consider
  • --allow <LOCATION> - Add to allow file
  • --reason <TEXT> - Reason for allowing

trace:

  • --target <FILE> - Target file to search in
  • --max-depth <N> - Maximum trace depth (default: 10)
  • --recursive - Trace into called functions

Allow Files

Patterns can be excluded via .moss/ allow files:

FilePurpose
.moss/large-files-allowExclude from analyze files
.moss/hotspots-allowExclude from analyze hotspots
.moss/duplicate-functions-allowExclude from duplicate detection
.moss/duplicate-types-allowExclude type pairs

Add via CLI:

bash
moss analyze files --allow "**/generated/*.rs" --reason "generated code"
moss analyze hotspots --allow "CHANGELOG.md" --reason "expected to change often"

Config

In .moss/config.toml:

toml
[analyze]
threshold = 10           # Default complexity threshold
compact = false          # Compact overview output
health = true            # Run health by default
complexity = true        # Run complexity by default
security = true          # Run security by default
duplicate_functions = false
exclude_interface_impls = true  # Exclude trait impls from doc coverage
hotspots_exclude = ["*.lock", "CHANGELOG.md"]

[analyze.weights]
health = 1.0
complexity = 0.5
security = 2.0
duplicate_functions = 0.3

Module Structure

analyze/
├── mod.rs        # Main dispatch, config
├── args.rs       # CLI argument definitions
├── report.rs     # Report formatting, grading
├── health.rs     # Health analysis
├── complexity.rs # Complexity metrics
├── security.rs   # Security patterns
├── files.rs      # File length analysis
├── hotspots.rs   # Git hotspots
├── duplicates.rs # Code clone detection
├── trace.rs      # Value provenance tracing
├── call_graph.rs # Caller/callee analysis
├── docs.rs       # Documentation coverage
├── lint.rs       # Linter integration
└── ...