Fast PHP inspector + fixer written in Go. Its rule catalogue includes native
inspections and rules modeled on Php Inspections (EA Extended); it is an
independent clean-room implementation released under MIT. Also runs as an
LSP server (custos lsp) for editors and an MCP server (custos mcp) for AI
agents.
Contributor docs (canonical, read before changing an area):
docs/contributing/ — index.md (make targets, code style, ground rules),
architecture.md (package ownership, contracts, helper placement),
adding-a-rule.md, clean-room.md, fixtures.md, releasing.md.
Per-root internal/*/AGENTS.md summarize ownership. Per-rule status:
docs/internals/rules.md.
Documentation describes current behavior and durable contributor practices.
Keep agent plans, progress logs and local verification reports in ignored
.cache/; never commit them as documentation. Keep catalogue totals in the
generated rule reference and status table, not in marketing or usage prose.
The upstream project (~/Sites/phpinspectionsea, LGPL-2.1) must never leak
into this repo. Full process: docs/contributing/clean-room.md.
- NEVER copy, translate or closely paraphrase EA Java code, messages, descriptions, docs or fixtures. No EA file is ever copied.
- Allowed facts only: rule IDs (EA short name minus
Inspection), groups, default severity/enabled flags, option names/defaults, PHP-version thresholds, all captured ininternal/inspection/meta/rules.jsonbymake extract. - Two separate agents/sessions per EA-modeled rule (skills in
.agents/skills/; for Claude Code, link them withln -s ../.agents/skills .claude/skills):spec-ruleskill: read EA, writespecs/<ID>.mdin our own words with new examples.implement-ruleskill: implement from the spec only; never open EA Java sources or EA fixtures while implementing.
- EA fixtures are only read at test time from the local checkout by
make conformance(severity and range of each finding + fix result compared; EA message text is never compared or stored).
Most of the catalogue is native: rules designed for custos with no EA
counterpart. Their IDs are our own, they have no PhpStorm name and no
conformance run, and their facts (group, severity, default, options) live in
internal/inspection/meta/native-rules.json, which make extract never
touches. Their spec is written directly in our own words; the implementation
step is the same. See docs/contributing/adding-a-rule.md.
Canonical ownership table: docs/contributing/architecture.md.
cmd/custos/ executable entry point
internal/php/ syntax, version, phpdoc
internal/semantic/ names, types, index, infer, flow, stubs
internal/inspection/ analysis, meta, catalogue, phpunit, {ast,flow,semantic}query
internal/inspection/rules/<id>/ rule.go (New), implementation, tests, testdata/, optional NOTES.md
internal/format/ formatter: settings registry, presets, gap engine; editorconfig/
internal/diagnostic/ internal/fixing/ findings and edits; fix application
internal/project/ discovery, indexing, analysis, prepared fixes; config, baseline
internal/output/ internal/cli/ internal/editor/{lsp,mcp}/ adapters
internal/platform/safeio/ internal/testing/ bounded IO; conformance harness, test budgets
pkg/custos/ pkg/custos/ast/ public Go API: rules written in Go, custom binaries (custos.Main)
examples/custom-binary/ example program using the public API (own module)
tools/ generators, architecture, coverage, clean-room checks
specs/ clean-room behavioral spec per rule ID
bench/ competitor benchmark: tools, versions, configs, results (tools/benchcmp)
docs/ VitePress guide, contributing docs, generated rules
make build # bin/custos
make test # go test ./...
make lint # golangci-lint + actionlint + editorconfig-checker + markdownlint (pinned; GOLANGCI=/ACTIONLINT=/ECCHECK=/MDLINT= to skip)
make vet / fmt-check # govet only / formatter diff (both part of lint)
make fmt # gofumpt + goimports + markdownlint --fix (run before committing)
make extract # regenerate rule facts + local EA index (EA_PATH=~/Sites/phpinspectionsea), then rules-doc
make rules-doc # regenerate the inspection catalogue, docs/rules/ (site), docs/internals/rules.md, explain texts
make fixtures # own fixtures (CI gate) RULE=<ID> to filter
make conformance # EA fixtures from local checkout RULE=<ID> to filter
make bench / fuzz
make compare # competitor benchmark → bench/results.json + docs/guide/benchmark.md (TOOL=/CORPUS= filter; compare-doc renders only)
make cleanroom # forbidden upstream tokens; verbatim EA text when the checkout exists
make docs / docs-dev # build / serve the docs site (Node 20+, docs/package.json)
make coverage # 100% gates: internal/inspection/rules from own fixtures + rule and catalogue tests; cmd/ + internal/ + tools/ from the whole suite
make architecture # package boundaries, complete inspection catalogue, rule package comments, fixture names
make examples # build the example programs using the public Go API (pkg/custos)
make verify # definition of done: architecture + lint + test + examples + fixtures + coverage + cleanroom
make stubs # rebuild embedded PHP stubs index
make deprecations # regenerate DeprecatedFeature's table (DEPRECATION_PHP="8.0=/path/php ..."; one binary per release)
make corpus-baseline / corpus-diff # record every rule's findings on the pinned bench corpora / fail on any change (CORPORA= filter)
make typecov # share of unknown inferred types on the bench corpora, by kind and cause (.cache/typecov/)
make mutations # report fixture findings that survive when assigned calls become closures (.cache/mutations.json)
make fixcheck # apply every quick-fix on CUSTOS_CORPUS, require parsable output (FIXCHECK=php adds php -l samples; FIXCHECK_TIMEOUT=90m for laravel)
make clean # remove bin/, dist/ and docs build output
go generate ./internal/php/syntax # regenerate node kinds after editing ast.go
- Binaries go to
bin/at the repository root: build withmake build(→bin/custos) orgo build -o bin/<name> ./cmd/<name>; never run a barego build ./cmd/...(it drops a binary in the working directory). Usego build ./...orgo vet ./...to only check compilation. - Go 1.27, standard library first; no new dependency without a clear reason.
- Performance is a feature: single AST walk per file with kind-indexed rule
dispatch, arena-allocated nodes, lazy semantic data, parallel files. Add a
benchmark for any hot path you touch; check
-benchmemallocations. - Byte offsets (
uint32) everywhere; fixes are text edits on exact ranges. - Rule IDs: for EA rules, the EA short name without
Inspection;@noinspection <LegacyID>and@custos-ignore <ID>must both suppress. Native rules have only their ID. - Severity mapping: EA ERROR→error, WARNING→warning, WEAK WARNING→info.
- Correctness beats upstream fidelity: when EA behavior is wrong (false
positives, fixes changing semantics or producing invalid PHP), diverge,
document it in the spec's Divergences and in
internal/testing/conformance/testdata/ea-divergences.json. - No rule lands without own fixtures in
internal/inspection/rules/<id>/testdata/(findings, the false positives it must avoid,.fixed.phpwhen it has a fix) covering 100% of its statements (make coverage; remove unreachable code rather than exempt it), and, for EA rules, a greenmake conformance RULE=<ID>(or a documented, justified divergence in the spec's "Divergences" section). - Specs are behavior only: no Go identifiers, repo paths, budget mechanics or
implementer advice; those go in an optional
NOTES.mdnext to the rule (format indocs/contributing/adding-a-rule.md). - Messages: short, imperative, our own wording; no
[EA]prefix. - Prose is US English (
behavior,analyze); "custos" stays lowercase, user docs say "rule" and "quick-fix". Theanalysecommand keeps its name. - PHP versions 5.3–8.6 supported: version-gate rules via
meta/spec thresholds. - New code ships with tests covering every statement (
make coverage); timing limits in tests usetestbudget.Of(d)(load-scaled) againsttestbudget.CPU()for compute-bound work, and hard performance budgets live inmake bench. - Order:
make rules-docwhen a spec, a rule's fixtures or rule status changes, thenmake verifybefore declaring work done. CI (docs.yml) fails whendocs/rules/or the rules sidebar is stale; the status table and explain texts are not checked, so regenerate them yourself. - Before committing, check the staged diff for user-visible changes and ensure
they are recorded under
## [Unreleased]inCHANGELOG.md. - User docs live in
docs/guide/(check claims against the real binary); never put<Tag>-like text or{{in prose outside code (Vue compiles the pages).
make architecture enforces production dependency direction and catalogue
completeness. Each inspection exposes New() analysis.Rule from rule.go
and is listed explicitly in internal/inspection/catalogue (generated by
go generate ./internal/inspection/catalogue); never import
another inspection or register through init(). Helper placement
(astquery / flowquery / semanticquery), the LSP WithIndex publication
boundary and adapter responsibilities are described once in
docs/contributing/architecture.md.