General repository policies
These policies work in any repository, whatever its language.
import { makePolicy, type RepopoConfig } from "repopo";import { LicenseFileExists, NoLargeBinaryFiles, RequiredGitignorePatterns,} from "repopo/policies";
export default { policies: [ makePolicy(LicenseFileExists), makePolicy(NoLargeBinaryFiles, { config: { maxSizeBytes: 5 * 1024 * 1024 } }), makePolicy(RequiredGitignorePatterns), ],} satisfies RepopoConfig;LicenseFileExists
Section titled “LicenseFileExists”Repository policy. Checks that a license file exists at the repository root. It runs once per check, including runs with --stdin and runs with empty stdin.
| Option | Type | Default | Description |
|---|---|---|---|
acceptedNames | string[] | LICENSE, LICENCE, and their .txt, .md, and .rst variants | File names that count as a license. |
Auto-fixable: No.
MaxChangedFiles
Section titled “MaxChangedFiles”Change policy (scope: "changes"). Reports a violation when the number of changed files exceeds a configured limit.
import { makePolicy, type RepopoConfig } from "repopo/api";import { MaxChangedFiles } from "repopo/policies";
export default { changes: { base: "main" }, policies: [ makePolicy(MaxChangedFiles, { config: { maxFiles: 50 }, exclude: ["^generated/"], }), ],} satisfies RepopoConfig;| Option | Type | Description |
|---|---|---|
maxFiles | number | Required nonnegative integer. Maximum number of changed files. Invalid values produce a policy execution error. |
The policy counts additions, modifications, deletions, type changes, and renames. Each rename counts once. Unchanged files do not count. Exactly maxFiles changes pass; a limit of zero permits an empty change set.
Global and per-policy exclusions remove files from the count. For renames, exclusions apply to the destination path, as with other repository policies. Stdin and file selections do not limit the count: the policy checks the full eligible change set, including when stdin is empty.
Use the existing PR, local, and staged change modes to select the change set. The policy uses the status snapshot captured before fixes, so fixes in the same run do not increase the count.
Auto-fixable: No. The finding reports the actual count and configured limit, with guidance to reduce or split the change. Enable the policy in your configuration; it has no default limit and does not run by default.
NoLargeBinaryFiles
Section titled “NoLargeBinaryFiles”Reports files larger than a size limit. Large files bloat the repository and slow down clones. Consider Git LFS for large assets.
| Option | Type | Default | Description |
|---|---|---|---|
maxSizeBytes | number | 10485760 (10 MB) | Largest allowed file size. |
excludeExtensions | string[] | Common text and source extensions (.md, .json, .ts, .css, .html, and more) | Extensions that are not checked. |
excludePatterns | string[] | Glob-style patterns (* wildcards) for files that are not checked. |
Auto-fixable: No.
RequiredGitignorePatterns
Section titled “RequiredGitignorePatterns”Checks that the root .gitignore contains required entries.
| Option | Type | Description |
|---|---|---|
patterns | Array<string | { pattern: string; comment?: string }> | Entries that must be present. With the object form, comment is inserted above the entry when fixing. |
When patterns isn’t set, the policy requires node_modules/, .env, .env.*, !.env.example, dist/, build/, .DS_Store, and Thumbs.db.
Auto-fixable: Yes. --fix appends missing entries.
RequireCompanionChanges
Section titled “RequireCompanionChanges”Change policy (scope: "changes"). Requires a related file update when a trigger path changes. For example, require a documentation change with source changes:
import { makePolicy, type RepopoConfig } from "repopo/api";import { RequireCompanionChanges } from "repopo/policies";
export default { changes: { base: "main" }, policies: [ makePolicy(RequireCompanionChanges, { instanceId: "source-needs-docs", config: { trigger: /^packages\/repopo\/src\//, companion: /^packages\/repopo-docs\//, }, }), ],} satisfies RepopoConfig;Both trigger and companion are required. Strings are case-insensitive regular expressions; RegExp values preserve their flags. Paths are relative to the repository root.
If any trigger path changes, at least one companion path must have an addition, modification, type change, or rename into its pattern. Deletions and both rename endpoints can trigger the rule. Deleting a companion or renaming it out of the pattern does not satisfy the requirement.
One instance expresses one requirement across the repository. Add separate instances with unique IDs for tests, docs, or changesets, or use package-specific patterns to restrict a rule to one package. Repopo does not infer package relationships. Overlapping trigger/companion patterns permit the same change to satisfy both.
The policy runs with empty stdin and checks changed statuses in the full annotated inventory. Unchanged companions do not satisfy the rule. Global and per-policy inventory exclusions apply, including to deleted entries. See change mode options.
Auto-fixable: No. Repopo reports matching trigger paths and guidance for the required update.