<commit_before>module RubyLint
  ##
  # {RubyLint::Runner} acts as an easy to use layer around the various parts of
  # ruby-lint. Pass it some files and a {RubyLint::Configuration} object and it
  # will take care of running code analysis, formatting it, etc.
  #
  # @!attribute [r] configuration
  #  @return [RubyLint::Configuration]
  #
  class Runner
    attr_reader :configuration

    ##
    # @param [RubyLint::Configuration] configuration
    #
    def initialize(configuration)
      @configuration = configuration
    end

    ##
    # Analyses the given files and returns the report results.
    #
    # @param [Array] files
    # @return [String]
    #
    def analyze(files)
      report    = Report.new(configuration.report_levels)
      presenter = configuration.presenter.new
      parser    = Parser.new

      parser.consumer = proc do |diag|
        report_diagnostic(diag, report)

        # FIXME: there's a bug in the pure Ruby version of Racc causing it hang
        # after detecting a syntax error (it stays forever in recovery mode).
        # To work around this we'll have to bail out after detecting the first
        # syntax error.
        return presenter.present(report)
      end

      files.each do |file|
        ast, comments = parse_file(parser, file)

        definitions = process_external_files(configuration.directories, ast)

        vm = run_vm(ast, comments, definitions)

        run_analysis(ast, vm, report)
      end

      return presenter.present(report)
    end

    private

    ##
    # Parses the given file and returns an Array containing all the associated
    # AST nodes and comments.
    #
    # @param [RubyLint::Parser] parser
    # @param [String] file
    # @return [Array]
    #
    def parse_file(parser, file)
      return parser.parse(File.read(file), file)
    end

    ##
    # Processes external Ruby files using {RubyLint::FileLoader}.
    #
    # @param [Array] directories
    # @param [RubyLint::AST::Node] root_ast
    # @return [Array]
    #
    def process_external_files(directories, root_ast)
      loader      = FileLoader.new(:directories => directories)
      definitions = []

      loader.iterate(root_ast)

      loader.nodes.each do |(ast, comments)|
        definitions << run_vm(ast, comments).definitions
      end

      return definitions
    end

    ##
    # @param [Parser::Diagnostic] diagnostic<commit_msg>Corrected a return value of the runner.<commit_after>module RubyLint
  ##
  # {RubyLint::Runner} acts as an easy to use layer around the various parts of
  # ruby-lint. Pass it some files and a {RubyLint::Configuration} object and it
  # will take care of running code analysis, formatting it, etc.
  #
  # @!attribute [r] configuration
  #  @return [RubyLint::Configuration]
  #
  class Runner
    attr_reader :configuration

    ##
    # @param [RubyLint::Configuration] configuration
    #
    def initialize(configuration)
      @configuration = configuration
    end

    ##
    # Analyses the given files and returns the report results.
    #
    # @param [Array] files
    # @return [String]
    #
    def analyze(files)
      report    = Report.new(configuration.report_levels)
      presenter = configuration.presenter.new
      parser    = Parser.new

      parser.consumer = proc do |diag|
        report_diagnostic(diag, report)

        # FIXME: there's a bug in the pure Ruby version of Racc causing it hang
        # after detecting a syntax error (it stays forever in recovery mode).
        # To work around this we'll have to bail out after detecting the first
        # syntax error.
        return presenter.present(report)
      end

      files.each do |file|
        ast, comments = parse_file(parser, file)

        definitions = process_external_files(configuration.directories, ast)

        vm = run_vm(ast, comments, definitions)

        run_analysis(ast, vm, report)
      end

      return presenter.present(report)
    end

    private

    ##
    # Parses the given file and returns an Array containing all the associated
    # AST nodes and comments.
    #
    # @param [RubyLint::Parser] parser
    # @param [String] file
    # @return [Array]
    #
    def parse_file(parser, file)
      return parser.parse(File.read(file), file)
    end

    ##
    # Processes external Ruby files using {RubyLint::FileLoader}.
    #
    # @param [Array] directories
    # @param [RubyLint::AST::Node] root_ast
    # @return [RubyLint::Definition::RubyObject]
    #
    def process_external_files(directories, root_ast)
      loader      = FileLoader.new(:directories => directories)
      definitions = []

      loader.iterate(root_ast)

      loader.nodes.each do |(ast, comments)|
        definitions << run_vm(ast, comments).definitions
      end

      return definitions
    end

    ##
    # @param [Parser::Diagnostic] diagnostic
{'fraction_non_alphanumeric': 0.08900308324768756, 'fraction_numerical': 0.0, 'mean_word_length': 2.6531531531531534, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '82061', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1348, 'n_words': 431}