Dependent Files Validator
Ensure related files are included in the PR
The Dependent Files Validator ensures that when certain files are modified, other related files are also included in the PR. This is useful for enforcing patterns like test coverage, documentation updates, or ensuring configuration changes are synchronized.
Configuration
Must be set to "dependent"
Configuration for dependent file relationships
Pattern matching files that trigger the dependency check
Pattern(s) for files that must be included when matching files are changed
Custom message to display when validation fails
Default message to display when validation fails
Basic Usage
Examples
Test Coverage Enforcement
Require test files for source code changes:
Multiple Required Files
Require multiple related files to be updated together:
Multiple Dependencies
Define different dependencies for different file types:
Using Placeholders
Use $
placeholder to reference the base filename:
How It Works
Get Changed Files
The validator retrieves all files changed in the PR
Process Dependencies
For each dependency rule:
- Find files matching the “when” pattern
- For each match, determine the required corresponding files
- Check if these required files are included in the PR
Handle Placeholders
Replaces placeholders (2, etc.) with captured groups from the pattern match
Return Result
Returns a validation result with status (pass, fail, or error) and a message
Pattern Matching
The Dependent Files Validator uses JavaScript regular expressions with capture groups:
src/(.+)\.js$
captures the path and filename (without extension) in$1
test/$1.test.js
uses the captured value to construct the expected test file path
Practical Use Cases
API and Documentation Sync
Ensure API changes are documented:
Schema and Migration Files
Ensure database schema changes include migrations:
Component and Test Updates
Enforce complete component updates:
Best Practices
Be careful with complex patterns that might be difficult for contributors to understand
Limitations
- Regular expressions can become complex for deeply nested directory structures
- Dependencies must be expressed as deterministic patterns
- Capturing multiple directory levels can be tricky