How to handle multiple definitions for the same constant in packwerk.yml with an ignored_definitions key

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.

Message originally sent by slack user U70NN25TNJA

That UX makes sense to us - awesome! :thumbsup_all: :sunglasses: :thumbsup_all:

For what it’s worth, our vote is for the flag option (--ambiguous) for that second feature (list-definitions). It feels like an explicit “filter” on the full set of definitions, and it’d be nice to do that without having to resort to grepping.