class SleepingKingStudios::Tasks::Ci::EslintResults
Encapsulates the results of an Eslint call.
Public Class Methods
new(results)
click to toggle source
@param results [Hash] The raw results of the Eslint call.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 9 def initialize results @results = results end
Public Instance Methods
==(other)
click to toggle source
@param other [EslintResults] The other results object to compare.
@return [Boolean] True if the results are equal, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 16 def == other if other.is_a?(Array) empty? ? other.empty? : @results == other elsif other.is_a?(EslintResults) to_h == other.to_h else false end end
empty?()
click to toggle source
@return [Boolean] True if there are no inspected files, otherwise false.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 27 def empty? inspected_file_count.zero? end
error_count()
click to toggle source
@return [Integer] The total number of error results across all files.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 32 def error_count @error_count ||= @results.map { |hsh| hsh['errorCount'] }.sum end
failing?()
click to toggle source
@return [Boolean] True if there are no errors or warnings, otherwise
false.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 38 def failing? !(error_count.zero? && warning_count.zero?) end
inspected_file_count()
click to toggle source
@return [Integer] The number of inspected files.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 43 def inspected_file_count @results.size end
pending?()
click to toggle source
@return [Boolean] Always false. Both warnings and errors trigger a failure
state.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 49 def pending? false end
to_h()
click to toggle source
@return [Hash] The hash representation of the results.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 54 def to_h { 'inspected_file_count' => inspected_file_count, 'error_count' => error_count, 'warning_count' => warning_count } end
to_s()
click to toggle source
@return [String] The string representation of the results.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 63 def to_s # rubocop:disable Metrics/AbcSize str = +"#{pluralize inspected_file_count, 'file'} inspected" str << ", #{pluralize error_count, 'error'}" str << ", #{pluralize warning_count, 'warning'}" str << "\n" unless non_empty_results.empty? non_empty_results.each do |hsh| str << "\n #{format_result_item(hsh)}" end str end
warning_count()
click to toggle source
@return [Integer] The total number of warning results across all files.
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 80 def warning_count @warning_count ||= @results.map { |hsh| hsh['warningCount'] }.sum end
Private Instance Methods
format_result_item(hsh)
click to toggle source
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 86 def format_result_item hsh str = +relative_path(hsh['filePath']) str << ": #{pluralize hsh['errorCount'], 'error'}" str << ", #{pluralize hsh['warningCount'], 'warning'}" end
non_empty_results()
click to toggle source
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 94 def non_empty_results @results.reject do |hsh| hsh['errorCount'].zero? && hsh['warningCount'].zero? end end
pluralize(count, singular, plural = nil)
click to toggle source
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 100 def pluralize count, singular, plural = nil "#{count} #{tools.int.pluralize count, singular, plural}" end
relative_path(path)
click to toggle source
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 104 def relative_path path path.sub(/\A#{Dir.getwd}#{File::SEPARATOR}?/, '') end
tools()
click to toggle source
# File lib/sleeping_king_studios/tasks/ci/eslint_results.rb, line 108 def tools SleepingKingStudios::Tools::Toolbelt.instance end