Skip to content

File Rules

File rules validate individual files based on glob patterns. They can enforce naming, schemas, frontmatter, and more.

files:
- id: typescript-source
glob: "src/**/*.ts"

This matches all .ts files under src/ and marks them as valid (not triggering no_matching_file_rule).

Enforce naming conventions on file paths:

files:
- id: source-files
glob: "src/**/*.ts"
pathCase: kebab
StyleValid ExampleInvalid Example
kebabmy-component.tsmyComponent.ts
camelmyComponent.tsmy-component.ts
pascalMyComponent.tsmyComponent.ts
snakemy_component.tsmy-component.ts

For advanced path validation:

files:
- id: strict-source
glob: "src/**/*.ts"
pathPattern: '^src/[a-z][a-z0-9-/]*\.ts$'

Validate file contents against JSON Schema:

files:
- id: package-json
glob: "package.json"
schema:
kind: json
schema: schemas/package.schema.json
- id: config-yaml
glob: "config/**/*.yaml"
schema:
kind: yaml
schema: schemas/config.schema.json

For markdown files, validate YAML frontmatter:

files:
- id: docs
glob: "docs/**/*.md"
frontmatter:
required:
- title
- description
schema: schemas/doc-frontmatter.schema.json

See Frontmatter Schemas for details.

Enforce that certain files have companions:

files:
- id: components
glob: "src/components/**/*.tsx"
requiredCompanion:
- pattern: "*.test.tsx" # Every component needs a test
- pattern: "*.css" # Every component needs styles

Block files containing sensitive patterns:

files:
- id: source-secrets
glob: "src/**/*.{ts,js}"
forbidContentPatterns:
- "API_KEY\\s*="
- "password\\s*[:=]"
- "BEGIN.*PRIVATE.*KEY"
- "sk-[a-zA-Z0-9]{20,}" # OpenAI keys
- "ghp_[a-zA-Z0-9]{36}" # GitHub PATs
- "npm_[a-zA-Z0-9]{36}" # npm tokens
- "xox[baprs]-[a-zA-Z0-9-]+" # Slack tokens
- id: env-files
glob: ".env*"
forbidContentPatterns:
- "sk-[a-zA-Z0-9]{20,}" # Real OpenAI keys
- "ghp_[a-zA-Z0-9]{36}" # Real GitHub tokens
- id: npmrc-safety
glob: ".npmrc"
forbidContentPatterns:
- "//registry.npmjs.org/:_authToken=" # Hardcoded npm tokens

Detect unfilled template placeholders:

files:
- id: docs
glob: "docs/**/*.md"
templateHints:
- "[Description]"
- "TODO:"
- "FIXME:"
- "XXX:"

These emit warnings, not errors.

A file can match multiple rules. All matching rules are applied:

files:
# Source TypeScript files
- id: typescript-source
glob: "src/**/*.ts"
pathCase: kebab
# Test files get additional rules
- id: test-files
glob: "src/**/*.test.ts"
requiredCompanion:
- pattern: "../*.ts" # Source file must exist
files:
- id: react-components
glob: "src/components/**/*.tsx"
pathCase: pascal
requiredCompanion:
- pattern: "*.test.tsx"
- pattern: "*.module.css"
files:
- id: api-routes
glob: "src/app/api/**/route.ts"
schema:
kind: json
schema: schemas/api-route.schema.json
files:
- id: json-configs
glob: "*.json"
schema:
kind: json
- id: env-files
glob: ".env*"
forbidContentPatterns:
- "sk-[a-zA-Z0-9]+" # OpenAI keys
- "ghp_[a-zA-Z0-9]+" # GitHub tokens

File rule violations produce these diagnostic codes:

CodeMeaning
no_matching_file_ruleFile doesn’t match any rule (deny mode)
path_case_violationFilename doesn’t match pathCase
path_pattern_violationPath doesn’t match pathPattern
json_schema_violationJSON content doesn’t match schema
yaml_schema_violationYAML content doesn’t match schema
missing_frontmatterMarkdown missing required frontmatter
frontmatter_schema_violationFrontmatter doesn’t match schema
missing_companion_fileRequired companion file doesn’t exist
forbidden_content_patternFile contains blocked pattern
template_hint_presentFile contains template placeholder