sverweij / dependency-cruiser

Validate and visualize dependencies. Your rules. JavaScript, TypeScript, CoffeeScript. ES6, CommonJS, AMD.
https://npmjs.com/dependency-cruiser
MIT License
5.21k stars 248 forks source link

Feature request: Dependency Cruiser as an eslint plugin #529

Open kyranjamie opened 2 years ago

kyranjamie commented 2 years ago

dependency-cruiser is awesome, it fills a tooling gap I've needed for a long time. Fantastisch werk @sverweij. While I do wish it worked with globs, at least it's a reason to become a regex pro.

For the Hiro Wallet, we're using depcruiser pretty extensively.

Nonetheless, it's another tool in our stack, and I'm curious about the viability of this being a eslint plugin. What I'd really like is a github & editor integrations, highlighting forbidden imports, so they can be fixed proactively, rather than reactively when our CI jobs fails. Think: eslint squiggly line under the import at dev-time.

Has this been considered? Are there implementation details that make this infeasible? Could a bridge be made between the two?

sverweij commented 2 years ago

Dank voor de vriendelijke woorden @kyranjamie :-)

I've indeed investigated implementing an eslint plugin for dependency-cruiser. To understand how eslint plugins work I even wrote a simple one (eslint-plugin-budapestian). It is possible to cover part of dependency-cruiser's (validation) functionality in an eslint plugin, but it will be a bit of an effort.

functionally

Other rules seem doable, though.

technically

Making an eslint plugin for dependency-cruiser rules would involve taking the AST as passed from eslint, pluck out the dependencies (requires, imports, exports, triple slash directives, exotics) and for each of them:

Other things:

Narretz commented 2 years ago

Interesting topic. I also think that an eslint plugin would be overkill, because eslint checks should be fast. Here are some ideas that come to mind:

pekala commented 2 years ago

I had a stab at this that you can check out here: https://github.com/pekala/eslint-plugin-dependency-cruiser It's fairly basic and only covers a subset of what could be done. I chose to run dependency-cruiser for each file at maxDepth: 1 so it performs ok for making changes to a single file, but when running a whole ESLint suite for a large codebase, it's very slow. Would love to brainstorm on ideas for how to make it better!