Class: SCSSLint::Reporter::StatsReporter

Inherits:
SCSSLint::Reporter show all
Defined in:
lib/scss_lint/reporter/stats_reporter.rb

Overview

Reports a single line per lint.

Instance Attribute Summary

Attributes inherited from SCSSLint::Reporter

#files, #lints, #log

Instance Method Summary collapse

Methods inherited from SCSSLint::Reporter

descendants, #initialize

Constructor Details

This class inherits a constructor from SCSSLint::Reporter

Instance Method Details

#organize_statsObject



29
30
31
32
33
34
35
36
37
# File 'lib/scss_lint/reporter/stats_reporter.rb', line 29

def organize_stats
  lints
    .group_by(&:linter)
    .sort_by { |_, lints_by_linter| -lints_by_linter.size }
    .inject([]) do |ary, (linter, lints_by_linter)|
      file_count = lints_by_linter.group_by(&:filename).size
      ary << [linter.name, lints_by_linter.size, file_count]
    end
end

#report_lintsObject

rubocop:disable Metrics/AbcSize



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/scss_lint/reporter/stats_reporter.rb', line 4

def report_lints # rubocop:disable Metrics/AbcSize
  return unless lints.any?

  stats = organize_stats
  total_lints = lints.length
  linter_name_length =
    stats.inject('') { |memo, stat| memo.length > stat[0].length ? memo : stat[0] }.length
  total_files = lints.group_by(&:filename).size

  # Math.log10(1) is 0; avoid this by using at least 1.
  lint_count_length = [1, Math.log10(total_lints).ceil].max
  file_count_length = [1, Math.log10(total_files).ceil].max

  str = ''
  stats.each do |linter_name, lint_count, file_count|
    str << "%#{lint_count_length}d  %-#{linter_name_length}s" % [lint_count, linter_name]
    str << "        (across %#{file_count_length}d files)\n" % [file_count]
  end
  str << "#{'-' * lint_count_length}  #{'-' * linter_name_length}"
  str << "        #{'-' * (file_count_length + 15)}\n"
  str << "%#{lint_count_length}d  #{'total'.ljust(linter_name_length)}" % total_lints
  str << "        (across %#{file_count_length}d files)\n" % total_files
  str
end