|
| 1 | +# Custom Rules |
| 2 | + |
| 3 | +Create custom rules to enforce your own policies, compliance requirements, or coding standards. |
| 4 | + |
| 5 | +## Quick Start |
| 6 | + |
| 7 | +1. **Create a source folder** under `sources/`: |
| 8 | + ``` |
| 9 | + sources/ |
| 10 | + ├── core/ # Project CodeGuard rules |
| 11 | + ├── owasp/ # OWASP supplementary rules |
| 12 | + └── my-rules/ # Your custom rules |
| 13 | + ``` |
| 14 | + |
| 15 | +2. **Copy the template** from `sources/templates/custom-rule-template.md.example` and customize it |
| 16 | + |
| 17 | +3. **Build with your rules**: |
| 18 | + ```bash |
| 19 | + uv run python src/convert_to_ide_formats.py --source core my-rules |
| 20 | + ``` |
| 21 | + |
| 22 | +## Frontmatter Schema |
| 23 | + |
| 24 | +| Field | Required | Description | |
| 25 | +|-------|----------|-------------| |
| 26 | +| `description` | Yes | Brief description of the rule | |
| 27 | +| `languages` | If `alwaysApply` is false | List of languages this rule applies to | |
| 28 | +| `alwaysApply` | No | If `true`, rule applies to all files (omit `languages`) | |
| 29 | +| `tags` | No | Categories for filtering: `authentication`, `data-security`, `infrastructure`, `privacy`, `secrets`, `web` | |
| 30 | + |
| 31 | +## CLI Reference |
| 32 | + |
| 33 | +### convert_to_ide_formats.py |
| 34 | + |
| 35 | +Converts source rules to IDE-specific formats. |
| 36 | + |
| 37 | +| Option | Description | |
| 38 | +|--------|-------------| |
| 39 | +| `--source` | Source folders under `sources/` to include. Default: `core` | |
| 40 | +| `--output-dir`, `-o` | Output directory for generated bundles. Default: `dist` | |
| 41 | +| `--tag` | Filter rules by tags (comma-separated, case-insensitive, AND logic) | |
| 42 | + |
| 43 | +**Examples:** |
| 44 | + |
| 45 | +```bash |
| 46 | +# Default: convert core rules only |
| 47 | +uv run python src/convert_to_ide_formats.py |
| 48 | + |
| 49 | +# Include multiple sources |
| 50 | +uv run python src/convert_to_ide_formats.py --source core owasp my-rules |
| 51 | + |
| 52 | +# Custom output directory |
| 53 | +uv run python src/convert_to_ide_formats.py --source core my-rules -o build |
| 54 | + |
| 55 | +# Filter to only rules tagged with data-security |
| 56 | +uv run python src/convert_to_ide_formats.py --tag data-security |
| 57 | + |
| 58 | +# Multiple tags (AND logic - rules must have ALL tags) |
| 59 | +uv run python src/convert_to_ide_formats.py --tag data-security,authentication |
| 60 | +``` |
| 61 | + |
| 62 | +### validate_unified_rules.py |
| 63 | + |
| 64 | +Validates rule files have correct frontmatter and structure before building. |
| 65 | + |
| 66 | +```bash |
| 67 | +# Validate all rules in a directory |
| 68 | +uv run python src/validate_unified_rules.py sources/my-rules/ |
| 69 | + |
| 70 | +# Validate all sources |
| 71 | +uv run python src/validate_unified_rules.py sources/ |
| 72 | +``` |
| 73 | + |
| 74 | +## Notes |
| 75 | + |
| 76 | +- Filenames must be unique across all sources |
| 77 | +- Use `.md` extension for all rule files |
| 78 | +- Rules are converted to all supported IDE formats |
| 79 | +- To add new tags, update `KNOWN_TAGS` in `src/tag_mappings.py` |
0 commit comments