<commit_before># typed: true
# frozen_string_literal: true

module Homebrew
  # Auditor for checking common violations in {Tap}s.
  #
  # @api private
  class TapAuditor
    extend T::Sig

    attr_reader :name, :path, :formula_names, :cask_tokens, :tap_audit_exceptions, :tap_style_exceptions,
                :tap_pypi_formula_mappings, :problems

    sig { params(tap: Tap, strict: T.nilable(T::Boolean)).void }
    def initialize(tap, strict:)
      @name                      = tap.name
      @path                      = tap.path
      @formula_names             = tap.formula_names
      @cask_tokens               = tap.cask_tokens
      @tap_audit_exceptions      = tap.audit_exceptions
      @tap_style_exceptions      = tap.style_exceptions
      @tap_pypi_formula_mappings = tap.pypi_formula_mappings
      @problems                  = []
    end

    sig { void }
    def audit
      audit_json_files
      audit_tap_formula_lists
    end

    sig { void }
    def audit_json_files
      json_patterns = Tap::HOMEBREW_TAP_JSON_FILES.map { |pattern| @path/pattern }
      Pathname.glob(json_patterns).each do |file|
        JSON.parse file.read
      rescue JSON::ParserError
        problem "#{file.to_s.delete_prefix("#{@path}/")} contains invalid JSON"
      end
    end
<commit_msg>tap_auditor: use short names when checking exception lists<commit_after># typed: true
# frozen_string_literal: true

module Homebrew
  # Auditor for checking common violations in {Tap}s.
  #
  # @api private
  class TapAuditor
    extend T::Sig

    attr_reader :name, :path, :formula_names, :cask_tokens, :tap_audit_exceptions, :tap_style_exceptions,
                :tap_pypi_formula_mappings, :problems

    sig { params(tap: Tap, strict: T.nilable(T::Boolean)).void }
    def initialize(tap, strict:)
      @name                      = tap.name
      @path                      = tap.path
      @cask_tokens               = tap.cask_tokens
      @tap_audit_exceptions      = tap.audit_exceptions
      @tap_style_exceptions      = tap.style_exceptions
      @tap_pypi_formula_mappings = tap.pypi_formula_mappings
      @problems                  = []

      @formula_names = tap.formula_names.map do |formula_name|
        formula_name.split("/").last
      end
    end

    sig { void }
    def audit
      audit_json_files
      audit_tap_formula_lists
    end

    sig { void }
    def audit_json_files
      json_patterns = Tap::HOMEBREW_TAP_JSON_FILES.map { |pattern| @path/pattern }
      Pathname.glob(json_patterns).each do |file|
        JSON.parse file.read
      rescue JSON::ParserError
        problem "#{file.to_s.delete_prefix("#{@path}/")} contains invalid JSON"
      end
    end

{'fraction_non_alphanumeric': 0.08781030011115228, 'fraction_numerical': 0.0, 'mean_word_length': 2.3707865168539324, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '903233', 'n_tokens_mistral': 911, 'n_tokens_neox': 841, 'n_words': 175}