# codemods/validators/reference.validator.ts

> 29 lines of code and 2 definitions.

Tree: Governance tree
Language: typescript
Layer: processing
Canonical: https://banes-lab.com/anatomy/governance#file-governance-codemods-validators-reference-validator-ts
Source text: https://banes-lab.com/source/governance/codemods/validators/reference.validator.ts.txt

Listed in [codemods/validators](https://banes-lab.com/api/source/governance/codemods/validators.md), after [codemods/validators/field.vocabulary.validator.ts](https://banes-lab.com/source/governance/codemods/validators/field.vocabulary.validator.ts.md).

## Definitions

- `findings` (lexical_declaration, line 14)
- `byConstruct` (lexical_declaration, line 21)

## Records this file checks

- [Traceability](https://banes-lab.com/records/architecture/traceability.md)

## Source

```typescript
import {
    GROUP_END,
    REFERENCES_CLEAN,
    constructGroupLine,
    referenceLine,
    referencesFailed,
} from "../strings/validation.strings.ts";
import type { ReferenceFinding } from "../../types/analyzer.types.ts";
import { collectReferenceFindings } from "../analyzers/reference.analyzer.ts";
import { defineCheck } from "@govlab/context/check";

defineCheck({ detects: [], enforces: ["architecture:traceability"] });

const findings = collectReferenceFindings();

if (findings.length === 0) {
    process.stdout.write(REFERENCES_CLEAN);
    process.exit(0);
}

const byConstruct = new Map<string, ReferenceFinding[]>();
for (const finding of findings) {
    byConstruct.set(finding.construct, [...(byConstruct.get(finding.construct) ?? []), finding]);
}

process.stderr.write(referencesFailed(findings.length));

for (const [construct, group] of [...byConstruct.entries()].sort((a, b) => b[1].length - a[1].length)) {
    process.stderr.write(constructGroupLine(construct, group.length));
    for (const finding of group) {
        process.stderr.write(referenceLine(finding.file, finding.value, finding.token));
    }
    process.stderr.write(GROUP_END);
}

process.exit(1);
```
