Repository: sverweij/dependency-cruiser (js)

Issue:
Feature request: reporters might report `comment` of rules other than `forbidden`
I'm filing it as a FR not as a Bug, because I'm not aware if it's by design or it's just that no one paid attention to it yet.

### Context

1. I have configuration containing not only `forbidden` (as the recommended has), but also [`required`](https://github.com/sverweij/dependency-cruiser/blob/main/doc/rules-reference.md#required)
1. My `required` rule has a `comment`.
1. I have one module that violates the `required` rule.
1. I execute
   ```sh
   depcruise src --output-type err-long
   ```

### Expected Behavior

1. I see violation reported
2. I see a comment

### Current Behavior

I do see violation reported, but I see `-` in place of the comment

### Possible Solution

I think it's caused by the fact that when

https://github.com/sverweij/dependency-cruiser/blob/9a523b4e16ceafb9a410875fe780462b5a6c052b/src/report/error.mjs#L108-L115

looks for comment it uses `findRuleByName` and it

https://github.com/sverweij/dependency-cruiser/blob/9a523b4e16ceafb9a410875fe780462b5a6c052b/src/graph-utl/rule-set.mjs#L12-L16

only looks through `forbidden`, it doesn't take other sections.

I see that making it

```diff
-  return (pRuleSet?.forbidden ?? []).find(
+  return ([
+    ...pRuleSet?.forbidden ?? [], 
+    ...pRuleSet?.allowed ?? [], 
+    ...pRuleSet?.required ?? [],
+  ]).find(
```

resolves the problem - I mean: if it's not meant **not** to find others but `forbidden`.
I'm happy to see it introduced as proposed (or as something that gives the same result), or I can create a PR, but if so - please let me know if feature this change touches has some tests or where can I add them

### Considered alternatives

I don't think I could rephrase my `required` rule into a `forbidden` - I'm a beginner in this tool (~2h so far, but "and counting" - I definitely see its potential), but lack of ability to see comments in output reduces its usefulness for me as repository maintainer in guiding developers through rules in my repository.


Pull request:
fix(graph-utl): lets findRuleByName also search in 'required' rules
## Description

- lets findRuleByName also search in 'required' rules

## Motivation and Context

fixes #930 

## How Has This Been Tested?

- [x] green ci
- [x] additional automated non-regression test

## Screenshots

With this rule added to dependency-cruiser's own config
```javascript
// ...
  "required": [
    {
      "name": "something-required",
      "comment": "Foo bar baz quux garply waldo fred plugh xyzzy thud",
      "severity": "warn",
      "module": {
        "path": "^src/meta.cjs$"
      },
      "to": {
        "path": "^test/kannie"
      }
    }
  ],
// ...
```

... `npx depcruise --progress -T err-long` shows this:


```
  warn something-required: src/meta.cjs
    Foo bar baz quux garply waldo fred plugh xyzzy thud


✘ 1 dependency violations (0 errors, 1 warnings). 545 modules, 1325 dependencies cruised.
⚠ 7 known violations ignored. Run with --no-ignore-known to see them.
```

## Types of changes

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without changing functionality)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)

## Checklist

- [x] :book:

  - My change doesn't require a documentation update, or ...
  - it _does_ and I have updated it

- [x] :balance_scale:
  - The contribution will be subject to [The MIT license](https://github.com/sverweij/dependency-cruiser/blob/main/LICENSE), and I'm OK with that.
  - The contribution is my own original work.
  - I am ok with the stuff in [**CONTRIBUTING.md**](https://github.com/sverweij/dependency-cruiser/blob/main/.github/CONTRIBUTING.md).


Patch:
diff --git a/src/graph-utl/rule-set.mjs b/src/graph-utl/rule-set.mjs
index fc464b99..ad05406a 100644
--- a/src/graph-utl/rule-set.mjs
+++ b/src/graph-utl/rule-set.mjs
@@ -10,9 +10,10 @@
  * @return {import("../../types/rule-set").IForbiddenRuleType|undefined} - a rule (or 'undefined' if nothing found)
  */
 export function findRuleByName(pRuleSet, pName) {
-  return (pRuleSet?.forbidden ?? []).find(
-    (pForbiddenRule) => pForbiddenRule.name === pName,
+  const lNamedRules = (pRuleSet?.forbidden ?? []).concat(
+    pRuleSet?.required ?? [],
   );
+  return lNamedRules.find((pRule) => pRule.name === pName);
 }
 
 function ruleHasALicenseLikeAttribute(pRule) {


Test patch:
diff --git a/test/graph-utl/rule-set.spec.mjs b/test/graph-utl/rule-set.spec.mjs
index d8a0e65e..19ce1626 100644
--- a/test/graph-utl/rule-set.spec.mjs
+++ b/test/graph-utl/rule-set.spec.mjs
@@ -34,6 +34,27 @@ describe("[U] graph-utl/rule-set - findRuleByName", () => {
       to: {},
     });
   });
+  it("also finds 'required' types rules, provided they're named", () => {
+    const lRuleSetWithRequiredRule = {
+      ...lRuleSet,
+      required: [
+        {
+          name: "some-required-rule",
+          comment: "heide does hok schapen",
+          severity: "warn",
+          from: {},
+          to: {},
+        },
+      ],
+    };
+    deepEqual(findRuleByName(lRuleSetWithRequiredRule, "some-required-rule"), {
+      name: "some-required-rule",
+      comment: "heide does hok schapen",
+      severity: "warn",
+      from: {},
+      to: {},
+    });
+  });
 });
 
 describe("[U] graph-utl/rule-set - ruleSetHasLicenseRule", () => {