Class: Overcommit::Hook::PreCommit::YardCoverage

Inherits:
Base
  • Object
show all
Defined in:
lib/overcommit/hook/pre_commit/yard_coverage.rb

Overview

Class to check yard documentation coverage.

Use option “min_coverage_percentage” in your YardCoverage configuration to set your desired documentation coverage percentage.

Instance Attribute Summary

Attributes inherited from Base

#config

Instance Method Summary collapse

Methods inherited from Base

#applicable_files, #command, #description, #enabled?, #execute, #execute_in_background, #flags, #in_path?, #included_files, #initialize, #name, #parallelize?, #processors, #quiet?, #required?, #required_executable, #required_libraries, #run?, #run_and_transform, #skip?

Constructor Details

This class inherits a constructor from Overcommit::Hook::Base

Instance Method Details

#runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/overcommit/hook/pre_commit/yard_coverage.rb', line 9

def run
  # Run a no-stats yard command to get the coverage
  args = flags + applicable_files
  result = execute(command, args: args)

  warnings_and_stats_text, undocumented_objects_text =
    result.stdout.split('Undocumented Objects:')

  warnings_and_stats = warnings_and_stats_text.strip.split("\n")

  # Stats are the last 7 lines before the undocumented objects
  stats = warnings_and_stats.slice(-7, 7)

  # If no stats present (shouldn't happen), warn the user and end
  if stats.class != Array || stats.length != 7
    return [:warn, 'Impossible to read the yard stats. Please, check your yard installation.']
  end

  # Check the yard coverage
  yard_coverage = check_yard_coverage(stats)
  if yard_coverage == :warn
    return [
      :warn,
      'Impossible to read yard doc coverage. Please, check your yard installation.'
    ]
  end
  return :pass if yard_coverage == :pass

  error_messages(yard_coverage, undocumented_objects_text)
end