<commit_before>module Hound
  module Tools
    class HoundConfig
      attr_reader :yaml
      attr_reader :rubocop_file
      attr_reader :rubocop_data

      def enabled?
        @enabled
      end

      def initialize(filename)
        @yaml = YAML.load(IO.read(filename))
        @enabled = @yaml['ruby'].fetch('enabled', true)
        @rubocop_file = @yaml['ruby'].fetch('config_file', nil)
        @rubocop_data = @rubocop_file && YAML.load(IO.read(@rubocop_file))
      end
    end

    class Runner
      DEFAULTS = {
        hound_yml_file: '.hound.yml',
        hound_ci_style_file: '.hound/defaults.yml',
        debug: false,
        glob_pattern: '**/*.rb' # TODO: should be all files?
      }

      def initialize(options)
        @options = DEFAULTS.merge(options)
      end

      def run
        # TODO: clean this up
        # TODO: not covered by specs

        hound_yml_file = @options[:hound_yml_file]
        hound_ci_style = @options[:hound_ci_style_file]
        debug = @options[:debug]
        glob_pattern = @options[:glob_pattern]

        # NOTE: the code below should be written to EXACTLY do what Hound does

        require 'rubocop'
        hound = HoundConfig.new(hound_yml_file)

        return "RuboCop disabled in #{hound_yml_file}" unless hound.enabled?

        # NOTE: treating hound.yml as a rubocop.yml file is deprecated
        custom = RuboCop::Config.new(hound.rubocop_data || hound.yml, '')
        custom.add_missing_namespaces
        custom.make_excludes_absolute

        default = RuboCop::ConfigLoader.configuration_from_file(hound_ci_style)
        config = RuboCop::ConfigLoader.merge(default, custom)

        cfg = RuboCop::Config.new(config, '')
        team = RuboCop::Cop::Team.new(RuboCop::Cop::Cop.all, cfg, debug: debug)<commit_msg>add debug option for loader (not used)<commit_after>module Hound
  module Tools
    class HoundConfig
      attr_reader :yaml
      attr_reader :rubocop_file
      attr_reader :rubocop_data

      def enabled?
        @enabled
      end

      def initialize(filename)
        @yaml = YAML.load(IO.read(filename))
        @enabled = @yaml['ruby'].fetch('enabled', true)
        @rubocop_file = @yaml['ruby'].fetch('config_file', nil)
        @rubocop_data = @rubocop_file && YAML.load(IO.read(@rubocop_file))
      end
    end

    class Runner
      DEFAULTS = {
        hound_yml_file: '.hound.yml',
        hound_ci_style_file: '.hound/defaults.yml',
        debug: false,
        glob_pattern: '**/*.rb' # TODO: should be all files?
      }

      def initialize(options)
        @options = DEFAULTS.merge(options)
      end

      def run
        # TODO: clean this up
        # TODO: not covered by specs

        hound_yml_file = @options[:hound_yml_file]
        hound_ci_style = @options[:hound_ci_style_file]
        debug = @options[:debug]
        glob_pattern = @options[:glob_pattern]

        # NOTE: the code below should be written to EXACTLY do what Hound does

        require 'rubocop'

        RuboCop::ConfigLoader.debug = debug
        hound = HoundConfig.new(hound_yml_file)

        return "RuboCop disabled in #{hound_yml_file}" unless hound.enabled?

        # NOTE: treating hound.yml as a rubocop.yml file is deprecated
        custom = RuboCop::Config.new(hound.rubocop_data || hound.yml, '')
        custom.add_missing_namespaces
        custom.make_excludes_absolute

        default = RuboCop::ConfigLoader.configuration_from_file(hound_ci_style)
        config = RuboCop::ConfigLoader.merge(default, custom)

        cfg = RuboCop::Config.new(config, '')
        team = RuboCop::Cop::Team.new(RuboCop::Cop::Cop.all, cfg, debug: debug)
{'fraction_non_alphanumeric': 0.10420076377523187, 'fraction_numerical': 0.0, 'mean_word_length': 2.616370808678501, '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': '7627189', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1144, 'n_words': 249}