Sha256: 9dc0ad2c266f9da5d61ee2fe73df1a23d689631a7e84056f6a09f6ec2f726bcc

Contents?: true

Size: 1.86 KB

Versions: 19

Compression:

Stored size: 1.86 KB

Contents

# typed: strict

module RuboCop
  module Cop
    module PackwerkLite
      module Private
        extend T::Sig

        sig { params(node: RuboCop::AST::ConstNode).returns(T::Boolean) }
        def self.partial_const_reference?(node)
          # This is a bit whacky, but if I have a reference in the code like this: Foo::Bar::Baz.any_method, `on_const` will be called three times:
          # One with `Foo`, one with `Foo::Bar`, and one with `Foo::Bar::Baz`.
          # As far as I can tell, there is no way to direct Rubocop to only look at the full constant name.
          # In order to ensure we're only operating on fully constant names, I check the "right sibling" of the `node`, which is the portion of the AST
          # immediately following the node.
          # If that right sibling is `nil` OR it's a lowercase string, we assume that it's the full constant.
          # If the right sibling is a non-nil capitalized string, we assume it's a part of the constant, because by convention, constants
          # start with capital letters and methods start with lowercase letters.
          # RegularRateOfPay::Types::HourlyEarningWithDate
          right_sibling = node.right_sibling
          return false if right_sibling.nil?

          right_sibling.to_s[0].capitalize == right_sibling.to_s[0]
        end

        sig { params(constant_reference: ConstantResolver::ConstantReference, type: String).returns(T::Boolean) }
        def self.violation_in_deprecated_references_yml?(constant_reference, type: 'privacy')
          existing_violations = ParsePackwerk::DeprecatedReferences.for(constant_reference.referencing_package).violations
          existing_violations.any? do |v|
            v.class_name == "::#{constant_reference.constant_name}" && (type == 'privacy' ? v.privacy? : v.dependency?)
          end
        end
      end

      private_constant :Private
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
rubocop-packs-0.0.30 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.29 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.28 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.27 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.26 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.25 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.24 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.23 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.22 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.21 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.20 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.19 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.18 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.17 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.16 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.15 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.14 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.13 lib/rubocop/cop/packwerk_lite/private.rb
rubocop-packs-0.0.12 lib/rubocop/cop/packwerk_lite/private.rb