# codemods/validators/field.vocabulary.validator.ts

> 21 lines of code and 4 definitions.

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

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

## Definitions

- `FAILURE` (lexical_declaration, line 9)
- `scope` (lexical_declaration, line 11)
- `found` (lexical_declaration, line 16)
- `plain` (lexical_declaration, line 17)

## Records this file checks

- [Closed Vocabulary](https://banes-lab.com/records/architecture/closed-vocabulary.md)

## Source

```typescript
import { CLOSED_SCOPE_LABEL, FIELD_SCOPES, PLAIN_CLOSED_FIELDS } from "../../shared/manifests/field.manifest.ts";
import { closedValuesLine, noClosedScope, plainClosedValue } from "../strings/validation.strings.ts";
import { defineCheck } from "@govlab/context/check";
import { plainClosedValues } from "../analyzers/field.vocabulary.analyzer.ts";
import process from "node:process";

defineCheck({ detects: [], enforces: ["architecture:closed-vocabulary"] });

const FAILURE = 1;

const scope = FIELD_SCOPES.find((entry) => entry.label === CLOSED_SCOPE_LABEL);
if (scope === undefined) {
    process.stderr.write(noClosedScope(CLOSED_SCOPE_LABEL));
    process.exit(FAILURE);
}
const found = plainClosedValues(scope);
const plain = found.filter((entry) => !PLAIN_CLOSED_FIELDS.has(entry.target));
process.stdout.write(closedValuesLine(found.length, found.length - plain.length, plain.length));
for (const entry of plain) {
    process.stderr.write(plainClosedValue(`${entry.file}:${String(entry.line)}`, entry.vocabulary, entry.target));
}
if (plain.length > 0) {
    process.exit(FAILURE);
}
```
