|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +`lc` (licensechecker) is a CLI tool that recursively scans directories to identify software licenses in files. It uses SPDX license identification with multiple detection strategies: SPDX header parsing, filename matching, and content analysis (keyword matching, vector space, Levenshtein distance). Written in Go, currently at v2.0.0 alpha. |
| 8 | + |
| 9 | +## Build & Development Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +go build # Build binary |
| 13 | +go test -cover -race ./... # Run all tests with coverage and race detection |
| 14 | +go test -v -run TestName ./processor/ # Run a single test |
| 15 | +gofmt -s -w ./.. # Format code |
| 16 | +golangci-lint run --enable gofmt ./... # Lint |
| 17 | +./check.sh # Full verification (fmt, test, lint, race, cross-compile) |
| 18 | +``` |
| 19 | + |
| 20 | +### Regenerating the License Database |
| 21 | + |
| 22 | +```bash |
| 23 | +./generate_database.sh # Build DB, copy JSON, run go generate, test |
| 24 | +``` |
| 25 | + |
| 26 | +This builds `assets/database/`, produces `database_keywords.json`, then `go generate` (via `scripts/include.go`) embeds it as base64 in `processor/constants.go`. |
| 27 | + |
| 28 | +## Architecture |
| 29 | + |
| 30 | +**Entry point:** `main.go` — Cobra CLI that creates `processor.NewProcess(".")` and calls `StartProcess()`. |
| 31 | + |
| 32 | +**`processor/` package** (active v2 code): |
| 33 | +- `processor.go` — Orchestrator: walks files via `gocodewalker`, reads content (max 100KB), routes through detection pipeline |
| 34 | +- `detector_spdx.go` — Parses `SPDX-License-Identifier:` headers from source files (100% confidence) |
| 35 | +- `detector_license.go` — Detects licenses in dedicated license files (LICENSE, COPYING, etc.) using filename regex matching |
| 36 | +- `guesser.go` — `LicenceGuesser` interface and framework; two instances: common licenses (fast path) and full database |
| 37 | +- `guesser_keyword.go` — Keyword-based license detection using Aho-Corasick |
| 38 | +- `guesser_vectorspace.go` — TF-IDF vector space similarity matching |
| 39 | +- `guesser_blended.go` — Combines keyword + vector space scores |
| 40 | +- `constants.go` — Auto-generated; contains base64-encoded license database (do not edit manually) |
| 41 | +- `structs.go` — Core data types (`FileResult`, `LicenseMatch`, etc.) |
| 42 | +- `common.go` — Shared utilities and compiled regex patterns for license filename detection |
| 43 | + |
| 44 | +**`parsers/` and `pkg/`** — Legacy v1 code, deprecated and scheduled for removal. |
| 45 | + |
| 46 | +**`assets/database/`** — Database builder that processes 425+ SPDX license definition files into `database_keywords.json`. |
| 47 | + |
| 48 | +## Detection Pipeline |
| 49 | + |
| 50 | +1. Check if file is binary (null byte detection) — skip unless `--binary` flag |
| 51 | +2. For files matching license filename patterns (license, copying, mit, apache, etc.): run through `LicenceGuesser` (keyword → vector space → blended) |
| 52 | +3. For all other files: scan for `SPDX-License-Identifier:` headers |
0 commit comments