This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
<@U70NN25TNJA> and <@U72GGKIGPTW>
Regarding UX around monkey patches and multiple definitions for the same constant…
I think what makes most sense to me at this point is an ignored_definitions key in packwerk.yml. It’d look like this:
ignored_definitions:
String:
- config/initializers/monkey_patch_string.rb
- app/services/other_monkey_patch.rb
MyDomainConstant::Submodule:
- path/to/definition/to/ignore.rb
...
The idea would be that for each use of a constant we’d create one reference, which means you could have multiple “violations” against the same constant (one for each definition).
ignored_definitions would give you sharp knife to ignore any of those definitions. There’s nothing about monkey patching in the API because packs doesn’t know that it’s a monkey patch (in the future it could look at redefinitions of std library as a monkey patch, but that’d be a net new feature).
Two additional behaviors/features could support this:
• packs check validates that ignored_definitions are not stale (e.g. monkey_patch_string.rb actually redefines String)
• packs list-definitions could have special notation to find constants defined multiple times (list-definitions | grep ambiguous), or a flag (e.g. --ambiguous) or a separate command list-ambiguous-definitions).
Let me know what ya think.