Skip to content

codecharter validate

Parse a single .ccr rule file and validate it against the schema.

codecharter validate <file>

<file> is the path to a single .ccr file. The command parses the file, compiles the LINQ expression against the schema, and prints the metadata once everything checks out.

Example

codecharter validate .codecharter/rules/repository-naming.ccr

Output on success:

Rule 'Repository class must end in Repository' parsed successfully
  Severity: error
  Category: Naming
  Description: Repositories must have a 'Repository' suffix for discoverability

On error:

Validation failed: Unknown property 'IsAsyncMethod' on MethodModel at line 8

Exit Codes

  • 0: Rule is valid.
  • 2: Validation error (parse, schema, or compile error).

As a pre-commit hook for rule files

#!/bin/sh
for file in $(git diff --cached --name-only --diff-filter=ACMR | grep '\.ccr$'); do
    codecharter validate "$file" || exit 1
done

This catches typos in .ccr files before the CI run sees them.