Rule Syntax
Rule Value Types
FS Guard supports several rule value types, each with different validation behavior:
Directory Exists: "*"
The simplest rule - validates that a directory exists:
typescript
{ rules: { "src": "*", "public": "*", "src/components": "*", }}This rule only checks for directory existence. Files and subdirectories are not validated.
Required Files: string[]
An array of required file names that must exist in the directory:
typescript
{ rules: { "src": ["index.ts", "App.tsx", "config.ts"], "public": ["index.html", "favicon.ico"], }}Each file in the array must exist. Missing files will cause validation to fail.
Pattern Matching: { pattern }
Validate that files match a specific pattern (glob syntax):
typescript
{ rules: { // All TypeScript files "src/types": { pattern: "*.ts" },
// Hook pattern "src/hooks": { pattern: "use*.ts" },
// Test files "tests": { pattern: "*.test.{ts,tsx}" }, }}Max Depth: { maxDepth }
Limit the maximum nesting depth of subdirectories:
typescript
{ rules: { // No subdirectories allowed "src/constants": { maxDepth: 0 },
// Up to 2 levels deep "src/utils": { maxDepth: 2 }, }}
// Valid: src/utils/string/format.ts (depth 2)// Invalid: src/utils/string/format/date.ts (depth 3)Required Directory: { required }
Mark a directory as required. This is implicit in most cases but can be combined with other rules:
typescript
{ rules: { "src/components": { required: true, pattern: "*.tsx" }, }}Combining Rules
Multiple rule properties can be combined for complex validation:
typescript
{ rules: { "src/hooks": { required: true, pattern: "use*.ts", maxDepth: 1 },
"src/services": { required: true, pattern: "*Service.ts", maxDepth: 2 }, }}Examples
| Rule | Validates |
|---|---|
| "src": "*" | Directory src/ exists |
| "src": ["index.ts"] | File src/index.ts exists |
| { pattern: "*.ts" } | All files match *.ts pattern |
| { maxDepth: 2 } | No subdirectories deeper than 2 levels |
| { required: true, pattern: "use*.ts" } | Directory exists and files match use*.ts |