Class: Packwerk::Visibility::Checker
- Inherits:
-
Object
- Object
- Packwerk::Visibility::Checker
- Extended by:
- T::Sig
- Includes:
- Checker
- Defined in:
- lib/packwerk/visibility/checker.rb
Overview
Checks whether a given reference references a constant from a package that does not permit visibility
Constant Summary collapse
- VIOLATION_TYPE =
T.let('visibility', String)
Instance Method Summary collapse
- #invalid_reference?(reference) ⇒ Boolean
- #message(reference) ⇒ Object
- #strict_mode_violation?(listed_offense) ⇒ Boolean
- #violation_type ⇒ Object
Instance Method Details
#invalid_reference?(reference) ⇒ Boolean
26 27 28 29 30 31 32 33 |
# File 'lib/packwerk/visibility/checker.rb', line 26 def invalid_reference?(reference) constant_package = reference.constant.package visibility_package = Package.from(constant_package) visibility_option = visibility_package.enforce_visibility return false if enforcement_disabled?(visibility_option) !visibility_package.visible_to.include?(reference.package.name) end |
#message(reference) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/packwerk/visibility/checker.rb', line 50 def (reference) source_desc = "'#{reference.package}'" = <<~MESSAGE Visibility violation: '#{reference.constant.name}' belongs to '#{reference.constant.package}', which is not visible to #{source_desc}. Is there a different package to use instead, or should '#{reference.constant.package}' also be visible to #{source_desc}? #{(reference)} MESSAGE .chomp end |
#strict_mode_violation?(listed_offense) ⇒ Boolean
40 41 42 43 |
# File 'lib/packwerk/visibility/checker.rb', line 40 def strict_mode_violation?(listed_offense) publishing_package = listed_offense.reference.constant.package publishing_package.config['enforce_visibility'] == 'strict' end |
#violation_type ⇒ Object
17 18 19 |
# File 'lib/packwerk/visibility/checker.rb', line 17 def violation_type VIOLATION_TYPE end |