<commit_before>module YARD
  module CLI
    class Stats < Yardoc
      include Templates::Helpers::BaseHelper
      
      # @return [Boolean] whether to parse and load registry
      attr_accessor :parse
      
      # @param [Boolean] parse whether to parse and load registry (see {#parse})
      def initialize(parse = true)
        super()
        @parse = parse
        @undoc_list = nil
        @compact = false
      end
      
      def description
        "Prints documentation statistics on a set of files"
      end
      
      # Runs the commandline utility, parsing arguments and generating
      # output if set.
      # 
      # @param [Array<String>] args the list of arguments
      # @return [void] 
      def run(*args)
        parse_arguments(*args)

        if @parse
          if use_cache
            Registry.load!
            checksums = Registry.checksums.dup
          end
          YARD.parse(files, excluded)
          Registry.save(use_cache)
        end
        
        print_statistics
        print_undocumented_objects
      end
      
      # Prints statistics for different object types
      # 
      # To add statistics for a specific type, add a method +#stats_for_TYPE+
      # to this class that calls {#output}.
      def print_statistics
        @total, @undocumented = 0, 0
        methods.map {|m| m.to_s }.grep(/^stats_for_/).each do |meth|
          send(meth)
        end
        total = (@total - @undocumented).to_f / @total.to_f * 100
        puts("% 3.2f%% documented" % total)
      end
      
      # Prints list of undocumented objects
      def print_undocumented_objects
        return unless @undoc_list
        puts
        puts "Undocumented Objects:"
        
        objects = @undoc_list.sort_by {|o| o.file }
        max = objects.sort_by {|o| o.path.length }.last.path.length
        if @compact
          objects.each do |object|
            puts("%-#{max}s     (%s)" % [object.path, object.file])
          end
        else
          last_file = nil
          objects.each do |object|
            if object.file != last_file
              puts
              puts "(in file: #{object.file})"
            end
            puts object.path
            last_file = object.file
          end
        end
      end
      
      # @return [Array<CodeObjects::Base>] all the parsed objects in the registry,
      #   removing any objects that are not visible (private, protected) depending
      #   on the arguments passed to the command.
      def all_objects
        @all_objects ||= run_verifier Registry.all
      end
      
      # Statistics for files
      def stats_for_files
        files = []
        all_objects.each {|o| files |= [o.file] }
        output "Files", files.size
      end
      
      # Statistics for modules
      def stats_for_modules
        output "Modules", *type_statistics(:module)
      end

      # Statistics for classes
      def stats_for_classes
        output "Classes", *type_statistics(:class)
      end
      
      # Statistics for constants
      def stats_for_constants
        output "Constants", *type_statistics(:constant)
      end

      # Statistics for methods
      def stats_for_methods
        objs = all_objects.select {|m| m.type == :method }
        objs.reject! {|m| m.is_alias? || !m.is_explicit? }
        undoc = objs.select {|m| m.docstring.blank? }
        @undoc_list |= undoc if @undoc_list
        output "Methods", objs.size, undoc.size
      end
      
      # Prints a statistic to standard out. This method is optimized for
      # getting Integer values, though it allows any data to be printed.
      # 
      # @param [String] name the statistic name
      # @param [Integer, String] data the numeric (or any) data representing
      #   the statistic. If +data+ is an Integer, it should represent the
      #   total objects of a type.
      # @param [Integer, nil] undoc number of undocumented objects for the type
      # @return [void]
      def output(name, data, undoc = nil)
        @total += data if data.is_a?(Integer) && undoc<commit_msg>Ignore overridden methods from "undocumented" check, they don't need documentation.<commit_after>module YARD
  module CLI
    class Stats < Yardoc
      include Templates::Helpers::BaseHelper
      
      # @return [Boolean] whether to parse and load registry
      attr_accessor :parse
      
      # @param [Boolean] parse whether to parse and load registry (see {#parse})
      def initialize(parse = true)
        super()
        @parse = parse
        @undoc_list = nil
        @compact = false
      end
      
      def description
        "Prints documentation statistics on a set of files"
      end
      
      # Runs the commandline utility, parsing arguments and generating
      # output if set.
      # 
      # @param [Array<String>] args the list of arguments
      # @return [void] 
      def run(*args)
        parse_arguments(*args)

        if @parse
          if use_cache
            Registry.load!
            checksums = Registry.checksums.dup
          end
          YARD.parse(files, excluded)
          Registry.save(use_cache)
        end
        
        print_statistics
        print_undocumented_objects
      end
      
      # Prints statistics for different object types
      # 
      # To add statistics for a specific type, add a method +#stats_for_TYPE+
      # to this class that calls {#output}.
      def print_statistics
        @total, @undocumented = 0, 0
        methods.map {|m| m.to_s }.grep(/^stats_for_/).each do |meth|
          send(meth)
        end
        total = (@total - @undocumented).to_f / @total.to_f * 100
        puts("% 3.2f%% documented" % total)
      end
      
      # Prints list of undocumented objects
      def print_undocumented_objects
        return unless @undoc_list
        puts
        puts "Undocumented Objects:"
        
        objects = @undoc_list.sort_by {|o| o.file }
        max = objects.sort_by {|o| o.path.length }.last.path.length
        if @compact
          objects.each do |object|
            puts("%-#{max}s     (%s)" % [object.path, object.file])
          end
        else
          last_file = nil
          objects.each do |object|
            if object.file != last_file
              puts
              puts "(in file: #{object.file})"
            end
            puts object.path
            last_file = object.file
          end
        end
      end
      
      # @return [Array<CodeObjects::Base>] all the parsed objects in the registry,
      #   removing any objects that are not visible (private, protected) depending
      #   on the arguments passed to the command.
      def all_objects
        @all_objects ||= run_verifier Registry.all
      end
      
      # Statistics for files
      def stats_for_files
        files = []
        all_objects.each {|o| files |= [o.file] }
        output "Files", files.size
      end
      
      # Statistics for modules
      def stats_for_modules
        output "Modules", *type_statistics(:module)
      end

      # Statistics for classes
      def stats_for_classes
        output "Classes", *type_statistics(:class)
      end
      
      # Statistics for constants
      def stats_for_constants
        output "Constants", *type_statistics(:constant)
      end

      # Statistics for methods
      def stats_for_methods
        objs = all_objects.select {|m| m.type == :method }
        objs.reject! {|m| m.is_alias? || !m.is_explicit? }
        undoc = objs.select {|m| m.docstring.blank? && !m.overridden_method }
        @undoc_list |= undoc if @undoc_list
        output "Methods", objs.size, undoc.size
      end
      
      # Prints a statistic to standard out. This method is optimized for
      # getting Integer values, though it allows any data to be printed.
      # 
      # @param [String] name the statistic name
      # @param [Integer, String] data the numeric (or any) data representing
      #   the statistic. If +data+ is an Integer, it should represent the
      #   total objects of a type.
      # @param [Integer, nil] undoc number of undocumented objects for the type
      # @return [void]
      def output(name, data, undoc = nil)
        @total += data if data.is_a?(Integer) && undoc
{'fraction_non_alphanumeric': 0.08337366892545983, 'fraction_numerical': 0.0016940948693126815, 'mean_word_length': 1.8737830319888735, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '4473091', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2301, 'n_words': 747}