CommitFence
Esc
↑ ↓ to moveEnter to open
Rules / The Settings File

The Settings File

commitfence.json: the rules of the team and the structure of the code, key by key.

On this page

commitfence.json#

The settings are one file, commitfence.json, at the top of the repository. commitfence init starts it with no rules. Every rules command, and review, takes --settings <path> to use another file.

Its first key is rules, a list. The order of the list is the order the rules are shown in; rules add takes --before <id> to put a new rule before another.

A rule#

KeyWhat it holds
idThe rule's name, such as TEAM010.
languagecsharp: C# is the only language reviewed.
forWhat the rule is about: if-statement, method, class or usage. See the rule catalog.
severityblock stops the push; warn only warns.
titleWhat the rule says, in a few words.
whereThe places the rule applies to: property names of the artifact, each with the value it must have. A list of values means any one of them.
requireWhat those places must be: property names and values. A rule has require or forbid, not both.
forbidtrue when the places where describes must not exist at all.
pathsA list of path patterns: the rule applies only to files that match one.
messageA message that goes with the rule.
whyThe reason the rule exists.

A rule that forbids a use of an API, limited to some paths and carrying its reason, as this repository's own commitfence.json has it (the list of types shortened here):

commitfence.json
{    "id": "TEAM013",    "language": "csharp",    "for": "usage",    "severity": "block",    "title": "Core uses no file, process or network API",    "where": {        "targetType": [            "System.IO.File",            "System.IO.Directory",            "…"        ]    },    "forbid": true,    "paths": [        "Dependencies/CF.Core/**"    ],    "why": "Core touches files, processes and the network only through its ports (IFileSystem, IProcessRunner and the others), so that a check can replace them and the adapters stay the only place that does real work."}

Structure#

Structure rules say which parts of the code may use which, and a push that makes that worse is refused. The structure key names the modules, each as a list of what belongs to it (namespace: and project:), and the directions that are allowed, each written from -> to. An excerpt of this repository's own file:

commitfence.json
{    "structure": {        "modules": {            "core": [                "namespace:CF.Core",                "project:CF.Core"            ],            "csharp": [                "namespace:CF.Languages.CSharp",                "project:CF.Languages.CSharp"            ],            "adapters": [                "namespace:CF.Adapters",                "project:CF.Adapters"            ],            "cli": [                "namespace:CF.Cli",                "project:commitfence"            ]        },        "directions": {            "allow": [                "csharp -> core",                "adapters -> core",                "cli -> composition"            ]        }    }}

Requiring a version#

A repository can require a newest-enough CommitFence with the requires key.

Where rules come from#

The rules of commitfence.json are the team's. The rules of .editorconfig are read from that file and are never changed by CommitFence: see Rules of .editorconfig.

Something wrong or unclear on this page? Tell us on GitHub