|
| 1 | +--- |
| 2 | +module: cmd_rules |
| 3 | +version: 1 |
| 4 | +status: stable |
| 5 | +files: |
| 6 | + - src/commands/rules.rs |
| 7 | +db_tables: [] |
| 8 | +tracks: [] |
| 9 | +depends_on: |
| 10 | + - specs/commands/commands.spec.md |
| 11 | + - specs/config/config.spec.md |
| 12 | + - specs/types/types.spec.md |
| 13 | +--- |
| 14 | + |
| 15 | +# Cmd Rules |
| 16 | + |
| 17 | +## Purpose |
| 18 | + |
| 19 | +Implements the `specsync rules` command. Lists all active validation rules — both built-in (from `specsync.json` `rules` section) and custom declarative rules (from `customRules` array). Shows configuration status, severity, rule type, and filter criteria. |
| 20 | + |
| 21 | +## Public API |
| 22 | + |
| 23 | +### Exported Functions |
| 24 | + |
| 25 | +| Function | Parameters | Returns | Description | |
| 26 | +|----------|-----------|---------|-------------| |
| 27 | +| `cmd_rules` | `root: &Path` | `()` | Load config and display all built-in and custom validation rules | |
| 28 | + |
| 29 | +### Internal Functions |
| 30 | + |
| 31 | +| Function | Parameters | Returns | Description | |
| 32 | +|----------|-----------|---------|-------------| |
| 33 | +| `print_builtin` | `name: &str, description: &str, value: Option<String>` | `()` | Print a built-in rule with its active/off status | |
| 34 | + |
| 35 | +## Invariants |
| 36 | + |
| 37 | +1. Built-in rules always display, showing "active" with value when configured or "off" when unset |
| 38 | +2. Five built-in rules listed: `max_changelog_entries`, `require_behavioral_examples`, `min_invariants`, `max_spec_size_kb`, `require_depends_on` |
| 39 | +3. Custom rules section only displays when `customRules` is non-empty; otherwise shows guidance to add them |
| 40 | +4. Each custom rule displays name, severity (color-coded), type, and optional section/pattern/min_words/applies_to/message fields |
| 41 | +5. Severity colors: error → red, warning → yellow, info → blue |
| 42 | + |
| 43 | +## Behavioral Examples |
| 44 | + |
| 45 | +### Scenario: No custom rules defined |
| 46 | + |
| 47 | +- **Given** `specsync.json` has no `customRules` array |
| 48 | +- **When** `specsync rules` runs |
| 49 | +- **Then** built-in rules are listed, followed by "No custom rules defined." with guidance text |
| 50 | + |
| 51 | +### Scenario: Custom rules with filters |
| 52 | + |
| 53 | +- **Given** a custom rule with `appliesTo: { status: "stable", module: "^auth" }` |
| 54 | +- **When** `specsync rules` runs |
| 55 | +- **Then** the rule shows `applies_to: status=stable, module=/^auth/` |
| 56 | + |
| 57 | +## Error Cases |
| 58 | + |
| 59 | +| Condition | Behavior | |
| 60 | +|-----------|----------| |
| 61 | +| Missing `specsync.json` | Config loader handles this (not this module's concern) | |
| 62 | + |
| 63 | +## Dependencies |
| 64 | + |
| 65 | +### Consumes |
| 66 | + |
| 67 | +| Module | What is used | |
| 68 | +|--------|-------------| |
| 69 | +| config | `load_config` | |
| 70 | +| types | `CustomRuleType`, `RuleSeverity` | |
| 71 | + |
| 72 | +### Consumed By |
| 73 | + |
| 74 | +| Module | What is used | |
| 75 | +|--------|-------------| |
| 76 | +| cli (main.rs) | Entry point for `specsync rules` | |
| 77 | + |
| 78 | +## Change Log |
| 79 | + |
| 80 | +| Date | Change | |
| 81 | +|------|--------| |
| 82 | +| 2026-04-10 | Initial spec | |
0 commit comments