Sha256: d1aa76838748b9d85bb212e176d5198ef80fc0a49839507e7f4c91448c865c7a
Contents?: true
Size: 1.76 KB
Versions: 4
Compression:
Stored size: 1.76 KB
Contents
# typed: strict # frozen_string_literal: true module ModularizationStatistics module Private module Metrics class RubocopProtectionsExclusions extend T::Sig sig { params(prefix: String, packages: T::Array[ParsePackwerk::Package], package_tags: T::Array[Tag]).returns(T::Array[GaugeMetric]) } def self.get_rubocop_exclusions(prefix, packages, package_tags) protected_packages = packages.map { |p| PackageProtections::ProtectedPackage.from(p) } rubocop_based_package_protections = T.cast(PackageProtections.all.select { |p| p.is_a?(PackageProtections::RubocopProtectionInterface) }, T::Array[PackageProtections::RubocopProtectionInterface]) rubocop_based_package_protections.flat_map do |rubocop_based_package_protection| metric_name = "#{prefix}.#{rubocop_based_package_protection.identifier}.rubocop_exclusions.count" all_exclusions_count = ParsePackwerk.all.sum { |package| exclude_count_for_package_and_protection(package, rubocop_based_package_protection)} GaugeMetric.for(metric_name, all_exclusions_count, package_tags) end end # TODO: `rubocop-packs` may want to expose API for this sig { params(package: ParsePackwerk::Package, protection: PackageProtections::RubocopProtectionInterface).returns(Integer) } def self.exclude_count_for_package_and_protection(package, protection) rubocop_todo = package.directory.join('.rubocop_todo.yml') if rubocop_todo.exist? loaded_rubocop_todo = YAML.load_file(rubocop_todo) cop_config = loaded_rubocop_todo.fetch(protection.cop_name, {}) cop_config.fetch('Exclude', []).count else 0 end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems