How deepsourcecorp/globstar works
Project type and purpose
• Globstar is an open-source, CLI-driven static analysis toolkit (written in Go) that bundles a set of built-in and user-defined checkers (YAML or Go) to run AST-based code inspections via tree-sitter.
Main components
a. CLI Layer
• pkg/cli – parses commands (globstar check), handles flags, version, and invokes the test runner.
• cmd/* – entry points for helper binaries (e.g., genregistry, globstar alias).
b. Configuration & Registry
• pkg/config – loads global and repository-level settings (.globstar directory).
• cmd/genregistry & pkg/analysis/pattern_rule.go – discover and register built-in Go and YAML checkers.
c. Core Analysis Engine
• pkg/analysis + analysis/ folder – tree-sitter integration, AST walker, multi-file scope resolution, matcher engine.
• Language modules – per‐language hooks (e.g., analysis/ts_scope.go, checkers/javascript/js_dataflow.go, etc.).
d. Checker Definitions
• YAML checkers (in checkers/*/*.yml) – simple S-expression queries.
• Go checkers (in checkers/*/*.go) – advanced logic using the analysis API.
e. Test Runner & Output
• pkg/cli/test_runner.go & analysis/testrunner.go – feed file list into the engine, aggregate results, format output (console, JSON).
f. External & Packaging
• Tree-sitter parsers (third-party library) – for AST generation.
• Single-binary packaging via Go modules, goreleaser for distribution.
Relationships & Data Flow
• User runs globstar check → CLI parses flags → Config loader finds .globstar + built-in checkers → Registry builder aggregates checker metadata → Test runner walks the file system → Core engine uses tree-sitter to parse each source file → Applies each checker (YAML pattern or Go function) → Collects and formats findings → Outputs to stdout/CI.
Architectural Patterns & Design Principles
• Plugin/registry pattern for checkers (discovering via file conventions).
• Layered architecture: CLI → Config → Registry → Analysis Engine → Checkers → Output.
• Dependency injection of AST and scope into checker implementations.
• Single-binary design to simplify CI integration.
Final Checklist
• [ ] Rectangles for each major component with package/file labels.
• [ ] Clear distinction between built-in and user-provided checkers.