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

Issue: depcruise doesn't fail if the path patterns in from or to are never matched #980

Open
JavaScriptBach opened this issue Jan 6, 2025 · 3 comments
Labels
enhancement this will make dependency-cruiser sweeter

Comments

@JavaScriptBach
Copy link

Expected Behavior

If I write a reachability rule, and the paths defined in from or to don't resolve to actual files on disk, I've written an incorrect rule. It would be best if depcruise failed in this case so that the developer can catch and fix the rule. It also helps ensure that dependency tests continue to stay in sync as files are moved around.

Current Behavior

depcruise silently succeeds.

Possible Solution

Make depcruise fail if from or to are never matched by a file on disk.

Steps to Reproduce (for bugs)

I'm using 16.9.0-beta-1 and able to reproduce this with a simple rule of the form of

{
      from: {
        path: "path/that/doesnt/exist.ts",
      },
      to: {
        path: "path/that/exists.ts",
        reachable: true,
      },
    },

Context

I'm writing rules in depcruise, putting them in my CI, and I want them to continue to stay correct over time.

Your Environment

  • Version used: 16.9.0-beta-1
  • Node version: 20
  • Operating System and version: Ubuntu 22
@sverweij
Copy link
Owner

sverweij commented Jan 7, 2025

Hi @JavaScriptBach that's a good suggestion. Making dependency-cruiser fail might be a bit harsh (it'll be a breaking change - and there might be legitimate reasons to have something not match e.g. in the to parts of rules), but warning/ info messages should be just as useful.

I'll see if I can whip up something.

@JavaScriptBach
Copy link
Author

JavaScriptBach commented Jan 7, 2025

Thank you for your consideration! Out of curiosity, what is a legitimate reason to have to not match a file? I couldn't think of one because 1) I'd expect all imports to be resolvable to files, and 2) if either from or to never match, the rule is effectively a no-op.

@sverweij
Copy link
Owner

Out of curiosity, what is a legitimate reason to have to not match a file?

E.g. when the to isn't (and perhaps, depending on the rule) shouldn't be part of the dependency-graph altogether. Two examples:

// .dependency-cruiser.mjs
export default {
  forbidden: [
    {
      name: "no-deprecated-core",
      from: {},
      to: {
        dependencyTypes: ["core"],
        path: [
          "^v8/tools/codemap$",
          "^v8/tools/consarray$",
          "^v8/tools/csvparser$",
         // ...
       ]
      }
    },
    {
      name: "not-to-dist",
      from: {
        path: "^src/",
      },
      to: {
        path: "^dist/",
      }
    },
  ]
}

@sverweij sverweij added the enhancement this will make dependency-cruiser sweeter label Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement this will make dependency-cruiser sweeter
Projects
None yet
Development

No branches or pull requests

2 participants