Class: Packwerk::Visibility::Checker

Inherits:
Object
  • Object
show all
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

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 message(reference)
  source_desc = "'#{reference.package}'"

  message = "    Visibility violation: '\#{reference.constant.name}' belongs to '\#{reference.constant.package}', which is not visible to \#{source_desc}.\n    Is there a different package to use instead, or should '\#{reference.constant.package}' also be visible to \#{source_desc}?\n\n    \#{standard_help_message(reference)}\n  MESSAGE\n\n  message.chomp\nend\n"

#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_typeObject



17
18
19
# File 'lib/packwerk/visibility/checker.rb', line 17

def violation_type
  VIOLATION_TYPE
end