Sha256: fa057f1ec3c1e36ead2a5c2caaa6c6afcb884df7e32db62233008971fe869c93

Contents?: true

Size: 1.77 KB

Versions: 10

Compression:

Stored size: 1.77 KB

Contents

# typed: strict

module DangerPackwerk
  module Private
    class DefaultAddedOffensesFormatter
      extend T::Sig

      sig { params(violations: T::Array[BasicReferenceOffense]).returns(String) }
      def self.format(violations)
        violation = T.must(violations.first)
        # We remove leading double colons as they feel like an implementation detail of packwerk.
        constant_name = violation.class_name.gsub(/\A::/, '')
        link_to_docs = '[the docs](https://github.com/Shopify/packwerk/blob/b647594f93c8922c038255a7aaca125d391a1fbf/docs/new_violation_flow_chart.pdf)'
        disclaimer = "We noticed you ran `bin/packwerk update-deprecations`. Make sure to read through #{link_to_docs} for other ways to resolve. "
        pluralized_violation = violations.count > 1 ? 'these violations' : 'this violation'
        request_to_add_context = "Could you add some context as a reply here about why we needed to add #{pluralized_violation}?"

        if violations.any?(&:dependency?) && violations.any?(&:privacy?)
          <<~MESSAGE
            Hi! It looks like the pack defining `#{constant_name}` considers this private API, and it's also not in the referencing pack's list of dependencies.
            #{disclaimer}#{request_to_add_context}
          MESSAGE
        elsif violations.any?(&:dependency?)
          <<~MESSAGE
            Hi! It looks like the pack defining `#{constant_name}` is not in the referencing pack's list of dependencies.
            #{disclaimer}#{request_to_add_context}
          MESSAGE
        else # violations.any?(&:privacy?)
          <<~MESSAGE
            Hi! It looks like the pack defining `#{constant_name}` considers this private API.
            #{disclaimer}#{request_to_add_context}
          MESSAGE
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
danger-packwerk-0.7.1 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.7.0 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.6.0 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.5.0 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.4.0 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.3.0 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.2.3 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.1.3 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.1.2 lib/danger-packwerk/private/default_offenses_formatter.rb
danger-packwerk-0.1.1 lib/danger-packwerk/private/default_offenses_formatter.rb