dependency-cruiser icon indicating copy to clipboard operation
dependency-cruiser copied to clipboard

Feature request: match src-dst import paths using a callback

Open tlaitinen opened this issue 1 year ago • 3 comments

Many thanks for this wonderful tool. Have you considered allowing to specify a callback in a rule instead of a pair of regular expressions? With a callback, users could encode arbitrary rules when regular expressions fall short or are challenging to implement.

Context

We have a complex code base and we want to implement very strict recursive import restrictions.

Expected Behavior

{
  "name": "complex-rule",
  "comment": "A comment about the rule",
  "severity": "error",
  "test": (src,dst) => { /* return true if the import src-dst is allowed */ }
}

Current Behavior

This question is just to find out what you think about the possibility of using callbacks, so I'm not including a detailed example at this point.

Possible Solution

If you are open to such an idea, we can provide a proof-of-concept implementation.

Considered alternatives

It may be possible to encode some of the rules we'd like to have using the current rule set, but there are probably reasonable ideas that cannot be implemented using the available rules.

tlaitinen avatar Feb 06 '23 09:02 tlaitinen