Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adds 'ancestor' matcher #961

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
126 changes: 126 additions & 0 deletions .dependency-cruiser-known-violations.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,132 @@
"name": "not-reachable-from-folder-index"
}
},
{
"type": "dependency",
"from": "src/cli/init-config/environment-helpers.mjs",
"to": "src/cli/defaults.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/cli/init-config/index.mjs",
"to": "src/cli/defaults.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/cli/init-config/write-run-scripts-to-manifest.mjs",
"to": "src/cli/defaults.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/enrich/derive/dependents/get-dependents.mjs",
"to": "src/enrich/derive/module-utl.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/enrich/derive/folders/aggregate-to-folders.mjs",
"to": "src/enrich/derive/circular.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/enrich/derive/folders/aggregate-to-folders.mjs",
"to": "src/enrich/derive/module-utl.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/enrich/derive/metrics/get-module-metrics.mjs",
"to": "src/enrich/derive/module-utl.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/enrich/derive/orphan/is-orphan.mjs",
"to": "src/enrich/derive/module-utl.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/extract/resolve/resolve.mjs",
"to": "src/extract/helpers.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/extract/swc/extract.mjs",
"to": "src/extract/helpers.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/extract/tsc/extract.mjs",
"to": "src/extract/helpers.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/main/options/normalize.mjs",
"to": "src/main/helpers.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/main/rule-set/assert-validity.mjs",
"to": "src/main/helpers.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "dependency",
"from": "src/main/rule-set/normalize.mjs",
"to": "src/main/helpers.mjs",
"rule": {
"severity": "info",
"name": "not-to-ancestor-folders"
}
},
{
"type": "module",
"from": "src/utl/extract-root-module-name.cjs",
Expand Down
24 changes: 24 additions & 0 deletions .dependency-cruiser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,30 @@ export default {
dependencyTypes: ["aliased-tsconfig-base-url"],
},
},
{
name: "not-to-ancestor-folders",
severity: "info",
from: {
path: "^src",
},
to: {
ancestor: true,
pathNot: "^src/meta[.]cjs$",
},
},
{
name: "not-outside",
severity: "ignore",
from: {
path: "^src/([^/]+/).+",
pathNot: "^src/(?:main|cli)/",
},
to: {
pathNot: ["^src/$1", "^src/(?:utl|graph-utl)/", "^src/meta[.]cjs$"],
dependencyTypesNot: ["npm", "core", "exotic-require", "type-only"],
couldNotResolve: false,
},
},
],
options: {
/* pattern specifying which files not to follow further when encountered
Expand Down
1 change: 1 addition & 0 deletions doc/assets/sample-ancestor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions doc/rules-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [rules on dependents - `numberOfDependentsLessThan`](#rules-on-dependents---numberOfDependentsLessThan)
- [rules on dependents - `numberOfDependentsMoreThan`](#rules-on-dependents---numberOfDependentsMoreThan)
- [`circular`](#circular)
- [`ancestor`](#ancestor)
- [`license` and `licenseNot`](#license-and-licensenot)
- [`dependencyTypes` and `dependencyTypesNot`](#dependencytypes-and-dependencytypesnot)
- [`dynamic`](#dynamic)
Expand Down Expand Up @@ -851,6 +852,27 @@ also displays [group matching](#group-matching).
}
```

### `ancestor`

Whether or not to match modules that are in a folder above the folder of the
module. This can be useful to prevent modules in a 'lower' folder to depend on
modules in a 'higher' folder.

```javascript
// in the `forbidden` section of a dependency-cruiser config:
{
name: "no-ancestor",
comment: "don't allow importing from folders above the current one",
severity: "error",
from: {},
to: { "ancestor": true }
}
```

For example, applied to the following dependency graph:

![ancestor](assets/sample-ancestor.svg)

### `license` and `licenseNot`

You can flag dependent modules that have licenses that are e.g. not
Expand Down
4 changes: 4 additions & 0 deletions src/schema/configuration.schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading