exe/gloc in gloc-0.7.0 vs exe/gloc in gloc-0.8.0

- old
+ new

@@ -1,22 +1,24 @@ #!/usr/bin/env ruby -s # -# rubocop:disable Layout/AlignHash +# rubocop:disable Layout/HashAlignment # rubocop:disable Layout/ElseAlignment # rubocop:disable Layout/EndAlignment # rubocop:disable Layout/IndentationWidth # +# rubocop:disable Lint/DuplicateBranch: +# # rubocop:disable Style/EmptyCaseCondition # rubocop:disable Style/GlobalVars # rubocop:disable Style/RegexpLiteral # require 'English' require 'ostruct' -source_files = if STDIN.tty? || $tty +source_files = if $stdin.tty? || $tty `git rev-parse --show-toplevel &> /dev/null` if $CHILD_STATUS.success? # we're inside a git repo so # get list of files from git `git ls-files -z #{ARGV.join(' ')}`.split("\0") @@ -25,12 +27,12 @@ # find all files in current dir `find #{ARGV.empty? ? Dir.pwd : ARGV.join(' ')} -print0`.split("\0") end else # assume we're running it in a pipeline - # and read list of filenames from STDIN - STDIN.read.split($RS).map(&:chomp) + # and read list of filenames from $stdin + $stdin.read.split($RS).map(&:chomp) end # exclude binary files from stats # (files with NUL in file header) # @@ -94,11 +96,11 @@ code_count: 0, ) end source_files.each do |file| - ext = '*' + File.extname(file) # e.g. '*.rb' or '*' if no ext! + ext = File.extname(file).prepend('*') # e.g. '*.rb' or '*' if no ext! blank_regex = BLANKS[ext] comment_regex = COMMENTS[ext] stats_for_file = STATS_FOR_FILE[[file, blank_regex, comment_regex]] @@ -118,21 +120,17 @@ when $comment then :comment_count when $code then :code_count else :code_count end -file_stats = Hash[ - STATS_FOR_FILE.sort_by { |_, stats| - stats.send(sort_metric) - }.reverse -] +file_stats = STATS_FOR_FILE.sort_by { |_, stats| + stats.send(sort_metric) +}.reverse.to_h -source_stats = Hash[ - STATS_FOR.sort_by { |_, stats| - stats.send(sort_metric) - }.reverse -] +source_stats = STATS_FOR.sort_by { |_, stats| + stats.send(sort_metric) +}.reverse.to_h source_stats['TOTAL'] = OpenStruct.new( file_count: source_stats.values.map(&:file_count).reduce(:+) || 0, line_count: source_stats.values.map(&:line_count).reduce(:+) || 0, blank_count: source_stats.values.map(&:blank_count).reduce(:+) || 0, @@ -142,11 +140,11 @@ # # JSON formatting for non-TTY output # -unless STDOUT.tty? || $tty || $visual +unless $stdout.tty? || $tty || $visual require 'json' class OpenStruct def to_json(*args) to_h.to_json(args) @@ -173,11 +171,11 @@ # # fancy formatting for TTY output # - source_stats.values.each do |stats_for_ext| + source_stats.each_value do |stats_for_ext| stats_for_ext.file_count = stats_for_ext.file_count.commify stats_for_ext.line_count = stats_for_ext.line_count.commify stats_for_ext.blank_count = stats_for_ext.blank_count.commify stats_for_ext.comment_count = stats_for_ext.comment_count.commify stats_for_ext.code_count = stats_for_ext.code_count.commify @@ -240,12 +238,14 @@ # # rubocop:enable Style/RegexpLiteral # rubocop:enable Style/GlobalVars # rubocop:enable Style/EmptyCaseCondition # +# rubocop:enable Lint/DuplicateBranch: +# # rubocop:enable Layout/IndentationWidth # rubocop:enable Layout/EndAlignment # rubocop:enable Layout/ElseAlignment -# rubocop:enable Layout/AlignHash +# rubocop:enable Layout/HashAlignment # # That's all Folks!