What are Rules?
Rules are the building blocks of your Rev-dep configuration. Each rule targets a specific directory in your project and defines which checks should run on files within that scope.Think of rules as isolated governance zones - each with its own set of quality standards and architectural constraints.
Rule Structure
Each rule in therules array has the following structure:
Rule Properties
Path Configuration
Target directory path for this rule.
- Use
"."for the root directory - Paths must be relative to the config file location
- Paths starting with
"./"are automatically normalized - Paths containing
"../"are rejected for security
Entry Points
Production entry point glob patterns.Used as default entry points for:
orphanFilesDetection(ifvalidEntryPointsnot specified)unusedExportsDetection(ifvalidEntryPointsnot specified)devDepsUsageOnProdDetection(ifprodEntryPointsnot specified)
Development entry point glob patterns.Combined with
prodEntryPoints as defaults for:orphanFilesDetection.validEntryPointsunusedExportsDetection.validEntryPoints
Monorepo Support
Control monorepo package resolution.Values:
true(default): Follow all workspace packagesfalse: Disable workspace package resolution["pkg1", "pkg2"]: Follow only specified package names
When enabled, Rev-dep resolves imports between monorepo packages and validates cross-package dependencies.
Check Configuration
Each rule can enable specific checks. Most checks support both single object and array formats:Single Detector (Most Common)
Multiple Detectors (Advanced)
Multiple detector instances allow you to run the same check with different configurations within a single rule.
Example Configurations
Entry Point Inheritance
Some detectors inherit entry points from rule-level configuration:Orphan Files Detection
Orphan Files Detection
If Example:
validEntryPoints is not specified in the detector config, it defaults to:Unused Exports Detection
Unused Exports Detection
If Exports from files matching these patterns are never reported as unused.
validEntryPoints is not specified, it defaults to:Dev Deps Usage on Prod Detection
Dev Deps Usage on Prod Detection
If
prodEntryPoints is not specified in the detector config, it defaults to the rule-level prodEntryPoints.Example:Running Specific Rules
You can run a subset of rules using the--rules flag:
Best Practices
Start Simple, Add Gradually
Start Simple, Add Gradually
Begin with basic checks enabled and gradually add more strict rules:
- Start with
circularImportsDetectionandunresolvedImportsDetection - Add
unusedNodeModulesDetectionandmissingNodeModulesDetection - Introduce
moduleBoundariesfor architecture enforcement - Enable
unusedExportsDetectionandorphanFilesDetectionwith autofix
Use Appropriate Granularity
Use Appropriate Granularity
Too few rules: Harder to configure different checks for different areasToo many rules: Slower execution, harder to maintainGood balance:
- One rule per monorepo package
- One rule per major feature domain
- Separate rules for frontend/backend if in same repo
Define Clear Entry Points
Define Clear Entry Points
Accurate entry points are critical for:
- Orphan file detection
- Unused exports detection
- Dev dependencies detection
Leverage Monorepo Package Following
Leverage Monorepo Package Following
For monorepo projects, enable
followMonorepoPackages to:- Resolve cross-package imports correctly
- Detect missing package.json dependencies
- Enforce boundaries between packages
Troubleshooting
No files found for this rule
No files found for this rule
Symptoms: Warning message
"No files found for this rule"Causes:- Incorrect
pathvalue - All files excluded by
ignoreFiles - Path doesn’t exist
- Verify the
pathis correct relative to config file - Check global
ignoreFilespatterns - Ensure the directory contains analyzable files (.js, .ts, .jsx, .tsx)
Rule path validation error
Rule path validation error
Symptoms: Error about invalid rule pathCauses:
- Path contains
"../" - Empty path
- Path with only
"./"
- Use
"."for root - Use subdirectory names without
"./"prefix:"packages/client" - Never use
"../"to go outside project
Missing package.json warning
Missing package.json warning
Symptoms: Warning about missing package.json in rule pathImpact:
- Node modules detection won’t work
- Monorepo package resolution may fail
- Ensure each rule path has a package.json file
- For monorepo packages, each package should have its own package.json
Next Steps
Available Checks
Explore all check types and their configuration
Module Boundaries
Enforce architectural constraints
Import Conventions
Standardize import styles
Config File Reference
Complete config schema documentation
