# core/plugins/manifest.governance.plugin.ts

> 31 lines of code and 7 definitions.

Tree: GovLab Docs
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/docs#file-docs-core-plugins-manifest-governance-plugin-ts
Source text: https://banes-lab.com/source/docs/core/plugins/manifest.governance.plugin.ts.txt

Listed in [core/plugins](https://banes-lab.com/api/source/docs/core/plugins.md), after [core/plugins/manifest.domain.plugin.ts](https://banes-lab.com/source/docs/core/plugins/manifest.domain.plugin.ts.md) and before [core/plugins/manifest.grammar.plugin.ts](https://banes-lab.com/source/docs/core/plugins/manifest.grammar.plugin.ts.md).

## Definitions

- `validate` (method_definition, line 19, exported)
- `contribute` (method_definition, line 11, exported)
- `REQUIRED_FIELDS` (lexical_declaration, line 7)
- `OPTIONAL_FIELDS` (lexical_declaration, line 8)
- `plugin` (lexical_declaration, line 10, exported)
- `declared` (lexical_declaration, line 20, exported)
- `optional` (lexical_declaration, line 27, exported)

## Contained in

- [core/plugins](https://banes-lab.com/anatomy/docs/folder-docs-core-plugins.md)

## Uses

- [configuration/strings/manifest.strings.ts](https://banes-lab.com/source/docs/configuration/strings/manifest.strings.ts.md)
- [core/predicates/readme.predicate.ts](https://banes-lab.com/source/docs/core/predicates/readme.predicate.ts.md)
- [core/predicates/record.predicate.ts](https://banes-lab.com/source/docs/core/predicates/record.predicate.ts.md)

## Linked from

- [configuration/strings](https://banes-lab.com/anatomy/docs/folder-docs-configuration-strings.md)
- [core/predicates](https://banes-lab.com/anatomy/docs/folder-docs-core-predicates.md)

## Source

```typescript
import { selfGovernedField, selfGovernedShape } from "#configuration/strings/manifest.strings";
import type { ManifestPlugin } from "#types/manifest.types";
import { SELF_GOVERNED_KEY } from "#configuration/constants/manifest.constants";
import { isNonEmptyString } from "#core/predicates/readme.predicate";
import { isPlainRecord } from "#core/predicates/record.predicate";

const REQUIRED_FIELDS: readonly string[] = ["checker", "paths"];
const OPTIONAL_FIELDS: readonly string[] = ["tests", "writes"];

export const plugin: ManifestPlugin = {
    contribute(manifest, entry) {
        if (isPlainRecord(manifest[SELF_GOVERNED_KEY])) {
            entry[SELF_GOVERNED_KEY] = true;
        }
    },
    name: "self-governance",
    section: {
        keys: [SELF_GOVERNED_KEY],
        validate(manifest) {
            const declared = manifest[SELF_GOVERNED_KEY];
            if (declared === undefined) {
                return [];
            }
            if (!isPlainRecord(declared)) {
                return [selfGovernedShape(SELF_GOVERNED_KEY)];
            }
            const optional = OPTIONAL_FIELDS.filter((field) => Object.hasOwn(declared, field));
            return [...REQUIRED_FIELDS, ...optional]
                .filter((field) => !isNonEmptyString(declared[field]))
                .map((field) => selfGovernedField(SELF_GOVERNED_KEY, field));
        },
    },
};
```
