Skip to content

Commit

Permalink
doc(types|rules-reference): adds the reachable attribute to the types…
Browse files Browse the repository at this point in the history
…, adds an example to the rules reference
  • Loading branch information
sverweij committed Dec 10, 2024
1 parent e984d85 commit fb99edc
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
36 changes: 33 additions & 3 deletions doc/rules-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ controller _must depend on_ the base controller'.
modules the rule applies to and the `to` describes what dependencies that module
should exactly have.

To check for _direct_ dependencies (controllers must directly depend on the
base controller):

```javascript
{
required: [
Expand All @@ -102,12 +105,39 @@ should exactly have.
"Each controller should inherit from the framework's base controller",
module: {
// every module that matches the pattern specified in path & pathNot ...
path: "-controller\\.js$",
pathNot: "framework/base-controller\\.js$",
path: "-controller[.]js$",
pathNot: "framework/base-controller[.]js$",
},
to: {
// ... must depend at least once on the framework's base controller
path: "^src/framework/base-controller[.]js$",
},
},
];
}
```

To check for _indirect_ ('transitive') dependencies (controllers must depend
on the base controller, either directly or via other modules) add the `reachable`
attribute to `to` part of the rule, like so:

```javascript
{
required: [
{
name: "controllers-transitively-inherit-from-base",
comment:
"Each controller should inherit from the framework's base controller",
module: {
// every module that matches the pattern specified in path & pathNot ...
path: "-controller[.]js$",
pathNot: "framework/base-controller[.]js$",
},
to: {
// ... must depend at least once on the framework's base controller
path: "^src/framework/base-controller\\.js$",
path: "^src/framework/base-controller[.]js$",
// ... either directly or indirectly
reachable: true,
},
},
];
Expand Down
4 changes: 4 additions & 0 deletions types/restrictions.d.mts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ export interface IRequiredToRestrictionType {
* one of the dependencies of the module should adhere to.
*/
path?: string | string[];
/**
* Whether or not to match transitive ('indirect') dependencies as well as direct ones.
*/
reachable?: boolean;
}

export interface IDependentsModuleRestrictionType extends IBaseRestrictionType {
Expand Down

0 comments on commit fb99edc

Please sign in to comment.