Skip to content

Commit e83b958

Browse files
Merge pull request #89 from project-codeguard/docs/custom-rules
Add custom rules documentation and template.
2 parents 73817a6 + eb495e3 commit e83b958

3 files changed

Lines changed: 112 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ python src/convert_to_ide_formats.py # Generate skills/ and dist/
7878
```
7979

8080
**More options**: `python src/convert_to_ide_formats.py --help`
81+
**Custom rules**: Create your own rules — see [Custom Rules](https://project-codeguard.org/custom-rules/)
8182
**Maintainers**: See [CONTRIBUTING.md](CONTRIBUTING.md) for release process.
8283

8384
## Community

docs/custom-rules.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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`
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
description: Brief description of the rule
3+
languages:
4+
- python
5+
- javascript
6+
tags:
7+
- data-security
8+
alwaysApply: false
9+
---
10+
11+
<!-- The content below is flexible - structure it to fit your use case -->
12+
13+
## Rule Title
14+
15+
Brief overview of what this rule enforces and why it matters.
16+
17+
### Section Name
18+
- Guidance point with specific recommendation
19+
- Another specific requirement or best practice
20+
21+
### Another Section
22+
- Additional guidance organized by topic
23+
- Keep points concise and actionable
24+
25+
### Implementation Checklist
26+
- Verify requirement one is met
27+
- Confirm requirement two is implemented
28+
- Check that patterns are followed
29+
30+
### Test Plan
31+
- Describe how to verify the rule is followed
32+
- Include specific test scenarios

0 commit comments

Comments
 (0)