For introspection (e.g. network graphs & graphs over time) as well as advanced enforcement regimes that may be difficult to implement in a packwerk checker extension it would be great to be able to get a list of all static constant references from a file or between all files.
Extracting constants references is where packwerk's core complexity lies and we should allow its reuse directly, without having to go through the more opinionated and specific logic built on top of it.
What approach did you choose and why?
I listed a naive approach in the first commit that doesn't require any modifications to existing packwerk code. This is the approach I currently use to generate detailed statistics about a monolith that I am working on. However, it uses a slew of private APIs.
In the second commit I propose a new module that creates public API for this functionality.
What should reviewers focus on?
Are we exposing more surface area than we need to? Anything specific we wouldn't want to expose?
Can you think of a cleaner way to implement this?
Caveats
I decided to raise on parser errors so we don't have to expose the Offense class and generally have a simpler interface. I'm happy to discuss other options.
The design of the RunContext class, which stems from a time when packwerk was a rubocop cop and we had to work around some of rubocop's limitations, is complex and entangled. Thus
it is difficult to pry apart, as you can see in the slightly awkward implementation of this feature
it is notoriously hard to test; indeed it doesn't have unit tests
Anything relying on RunContext is also hard to test, and so the tests included with this PR are not optimal
Type of Change
[ ] Bugfix
[X] New feature
[ ] Non-breaking change (a change that doesn't alter functionality - i.e., code refactor, configs, etc.)
What are you trying to accomplish?
For introspection (e.g. network graphs & graphs over time) as well as advanced enforcement regimes that may be difficult to implement in a packwerk checker extension it would be great to be able to get a list of all static constant references from a file or between all files.
Extracting constants references is where packwerk's core complexity lies and we should allow its reuse directly, without having to go through the more opinionated and specific logic built on top of it.
What approach did you choose and why?
I listed a naive approach in the first commit that doesn't require any modifications to existing packwerk code. This is the approach I currently use to generate detailed statistics about a monolith that I am working on. However, it uses a slew of private APIs.
In the second commit I propose a new module that creates public API for this functionality.
What should reviewers focus on?
Caveats
Type of Change
Checklist
Additional Notes
This work is sponsored by https://www.onemedical.com/