Class: Packwerk::FolderPrivacy::Checker
- Inherits:
-
Object
- Object
- Packwerk::FolderPrivacy::Checker
- Extended by:
- T::Sig
- Includes:
- Checker
- Defined in:
- lib/packwerk/folder_privacy/checker.rb
Constant Summary collapse
- VIOLATION_TYPE =
T.let('folder_privacy', 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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/packwerk/folder_privacy/checker.rb', line 25 def invalid_reference?(reference) referencing_package = reference.package referenced_package = reference.constant.package return false if enforcement_disabled?(Package.from(referenced_package).enforce_folder_privacy) # the root pack is parent folder of all packs, so we short-circuit this here referencing_package_is_root_pack = referencing_package.name == '.' return false if referencing_package_is_root_pack packages_are_sibling_folders = Pathname.new(referenced_package.name).dirname == Pathname.new(referencing_package.name).dirname return false if packages_are_sibling_folders referencing_package_is_parent_folder = Pathname.new(referenced_package.name).to_s.start_with?(referencing_package.name) return false if referencing_package_is_parent_folder true end |
#message(reference) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/packwerk/folder_privacy/checker.rb', line 59 def (reference) source_desc = "'#{reference.package}'" = <<~MESSAGE Folder Privacy violation: '#{reference.constant.name}' belongs to '#{reference.constant.package}', which is private to #{source_desc} as it is not a sibling pack or parent pack. 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
49 50 51 52 |
# File 'lib/packwerk/folder_privacy/checker.rb', line 49 def strict_mode_violation?(listed_offense) publishing_package = listed_offense.reference.constant.package publishing_package.config['enforce_folder_privacy'] == 'strict' end |
#violation_type ⇒ Object
16 17 18 |
# File 'lib/packwerk/folder_privacy/checker.rb', line 16 def violation_type VIOLATION_TYPE end |