[Bug Report] Explicitly private constants without `::` are ignored
exterm opened this issue · 2 comments
Description
If explicitly private constants are specified without the ::
prefix, they will not be matched when checking for privacy violations.
Specifying them in this way just does not have any effect.
To Reproduce
In a package a
defining MyConstant
at the top level (equivalent to ::MyConstant
), set enforce_privacy: ["MyConstant"]
.
From another package b
, add a reference to MyConstant
or ::MyConstant
.
Execute packwerk check --packages=b
.
Expected Behaviour
Packwerk reports an error for the reference to the private constant.
Actual Behavior
Packwerk reports no error.
Version Information
- Packwerk: 1.3.2
- Ruby 3.0.2p107
Additional Context
It works just fine if enforce_privacy
is set to ["::MyConstant"]
instead.
I see two possible solutions:
- Enhance the
ApplicationValidator
to reject explicitly private constants that are not explicitly top-level - or in other words, only accept values that start with::
- Better: Change the comparison code to that it assumes all explicitly private constants are top level.
Actually not that sure anymore the second proposed solution is better. It would look strange to have constants with and without ::
prefix in the same file.
Fixed in #163!