Sha256: 10db723cb5ea9799260b193c7d341453960a8ee655ce677b4b2065f295fd83bb

Contents?: true

Size: 1.73 KB

Versions: 3

Compression:

Stored size: 1.73 KB

Contents

# typed: strict
# frozen_string_literal: true

require 'rubocop-packs'

module ModularizationStatistics
  module Private
    module Metrics
      class PackwerkCheckerUsage
        extend T::Sig
        
        # Later, we might find a way we can get this directly from `packwerk`
        class PackwerkChecker < T::Struct
          const :setting, String
          const :strict_mode, String
        end

        sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) }
        def self.get_checker_metrics(prefix, packages, package_tags)
          metrics = T.let([], T::Array[GaugeMetric])

          checkers = [
            PackwerkChecker.new(setting: 'enforce_dependencies', strict_mode: 'enforce_dependencies_strictly'),
            PackwerkChecker.new(setting: 'enforce_privacy', strict_mode: 'enforce_privacy_strictly')
          ]

          checkers.each do |checker|
            ['false', 'true', 'strict'].each do |enabled_mode|
              count_of_packages = ParsePackwerk.all.count do |package|
                strict_mode = package.metadata[checker.strict_mode]
                enabled = YAML.load_file(package.yml)[checker.setting]
                case enabled_mode
                when 'false'
                  !enabled
                when 'true'
                  enabled && !strict_mode
                when 'strict'
                  !!strict_mode
                end
              end

              metric_name = "#{prefix}.packwerk_checkers.#{checker.setting}.#{enabled_mode}.count"
              metrics << GaugeMetric.for(metric_name, count_of_packages, package_tags)
            end
          end

          metrics
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
modularization_statistics-2.0.2 lib/modularization_statistics/private/metrics/packwerk_checker_usage.rb
modularization_statistics-2.0.1 lib/modularization_statistics/private/metrics/packwerk_checker_usage.rb
modularization_statistics-2.0.0 lib/modularization_statistics/private/metrics/packwerk_checker_usage.rb