Skip to content

Commit

Permalink
feature(validate): adds a dependents count validation (sverweij#449)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij authored Mar 22, 2021
1 parent e0e9f69 commit 59fdb49
Show file tree
Hide file tree
Showing 55 changed files with 1,441 additions and 255 deletions.
10 changes: 8 additions & 2 deletions .dependency-cruiser.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
},
{
"name": "not-reachable-from-folder-index",
"comment": "(sample rule to demo reachable rules with capturing groups)",
"severity": "info",
"from": {
"path": "^src/([^/]+)/index\\.js$"
Expand All @@ -189,6 +190,13 @@
"path": "^src/$1/",
"reachable": false
}
},
{
"name": "utl-module-not-shared-enough",
"comment": "(sample rule to demo demo rules based on dependents)",
"severity": "info",
"from": { "path": "^src" },
"module": { "path": "^src/utl", "numberOfDependentsLessThan": 3 }
}
],
"options": {
Expand Down Expand Up @@ -387,8 +395,6 @@
}
}
},
// "progress": { "type": "cli-feedback" }
"progress": { "type": "performance-log" }
// "progress": {"type": "none"}
}
}
7 changes: 7 additions & 0 deletions doc/options-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- [mono repo behaviour - combinedDependencies](#mono-repo-behaviour---combinedDependencies)
- [exotic ways to require modules - exoticRequireStrings](#exotic-ways-to-require-modules---exoticrequirestrings)
- [enhancedResolveOptions](#enhancedresolveoptions)
- [forceDeriveDependents](#forcederivedependents)

## Filters

Expand Down Expand Up @@ -1178,3 +1179,9 @@ E.g. to set the cache duration to 1337ms, you can use this:
The cache duration is limited from 0ms (~ don't use a cache) to 1800000ms (0.5h).
The cacheDuration used here overrides any that might be set in webpack configs.
### `forceDeriveDependents`
Dependency-cruiser will automatically determine whether it needs to derive dependents.
However, if you want to force them to be derived, you can switch this variable
to `true`.
40 changes: 40 additions & 0 deletions doc/recipes/internal-orphans/.dependency-cruiser-options-only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/** @type {import('dependency-cruiser').IConfiguration} */
/** @type {import('../../..').IConfiguration} */
module.exports = {
options: {
tsPreCompilationDeps: true,
baseDir: "src",

reporterOptions: {
dot: {
collapsePattern: "node_modules/[^/]+",
theme: {
graph: {
splines: "ortho",
rankdir: "TD",
},
modules: [
{
criteria: { source: "^common" },
attributes: { fillcolor: "#cccccc" },
},
],
dependencies: [
{
criteria: { "rules[0].severity": "error" },
attributes: { fontcolor: "red", color: "red" },
},
{
criteria: { "rules[0].severity": "warn" },
attributes: { fontcolor: "orange", color: "orange" },
},
{
criteria: { "rules[0].severity": "info" },
attributes: { fontcolor: "blue", color: "blue" },
},
],
},
},
},
},
};
17 changes: 17 additions & 0 deletions doc/recipes/internal-orphans/.dependency-cruiser-with-rules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const options = require("./.dependency-cruiser-options-only");

/** @type {import('dependency-cruiser').IConfiguration} */
module.exports = {
forbidden: [
{
name: "no-unshared-utl",
severity: "error",
from: {},
module: {
path: "^do-things/",
numberOfDependentsLessThan: 1,
},
},
],
...options,
};
155 changes: 155 additions & 0 deletions doc/recipes/internal-orphans/before.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 59fdb49

Please sign in to comment.