Class: Danger::DangerCheckstyleReports

Inherits:
Plugin
  • Object
show all
Defined in:
lib/checkstyle_reports/plugin.rb

Overview

Comment checkstyle reports.

You need to specify the project root. You don’t need do it if it is same with git’s top-level path.

checkstyle_reports.root_path=/path/to/project

Examples:

Report errors whose files have been modified (By default)


checkstyle_reports.report("app/build/checkstyle/checkstyle.xml"[, modified_files_only: true])

Report all errors in app/build/checkstyle/checkstyle.xml


checkstyle_reports.report("app/build/checkstyle/checkstyle.xml", modified_files_only: false)

Constant Summary collapse

REPORT_METHODS =
%i[message warn fail].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filteringObject

Enable filtering Only show messages within changed files.



60
61
62
# File 'lib/checkstyle_reports/plugin.rb', line 60

def filtering
  @filtering
end

#filtering_linesObject

Only show messages for the modified lines.



63
64
65
# File 'lib/checkstyle_reports/plugin.rb', line 63

def filtering_lines
  @filtering_lines
end

#inline_commentBoolean

Optional Create inline comment if true.

Returns:

  • (Boolean)

    true by default



44
45
46
# File 'lib/checkstyle_reports/plugin.rb', line 44

def inline_comment
  @inline_comment
end

#min_severityString, Symbol

Optional minimum severity to be reported (inclusive)

Returns:

  • (String, Symbol)

    error by default



50
51
52
# File 'lib/checkstyle_reports/plugin.rb', line 50

def min_severity
  @min_severity
end

#report_methodString, Symbol

Optional Set report method

Returns:

  • (String, Symbol)

    error by default



56
57
58
# File 'lib/checkstyle_reports/plugin.rb', line 56

def report_method
  @report_method
end

#reported_filesArray<String> (readonly)

The array of files which include at least one error

Returns:

  • (Array<String>)

    a collection of relative paths



68
69
70
# File 'lib/checkstyle_reports/plugin.rb', line 68

def reported_files
  @reported_files
end

#root_pathString

Optional An absolute path to a root. To comment errors to VCS, this needs to know relative path of files from the root.

Returns:

  • (String)

    the root path of git repository by default.



38
39
40
# File 'lib/checkstyle_reports/plugin.rb', line 38

def root_path
  @root_path
end

Instance Method Details

#report(xml_file, modified_files_only: true) ⇒ void

This method returns an undefined value.

Report errors based on the given xml file if needed

Parameters:

  • xml_file (String)

    which contains checkstyle results to be reported

  • modified_files_only (Boolean) (defaults to: true)

    which is a flag to filter out non-added/non-modified files



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/checkstyle_reports/plugin.rb', line 75

def report(xml_file, modified_files_only: true)
  raise 'File path must not be empty' if xml_file.empty?
  raise 'File not found' unless File.exist?(xml_file)

  @min_severity = (min_severity || :error).to_sym
  @report_method = (report_method || :fail).to_sym

  raise 'Unknown severity found' unless CheckstyleReports::Severity::VALUES.include?(min_severity)
  raise 'Unknown report method' unless REPORT_METHODS.include?(report_method)

  files = parse_xml(xml_file, modified_files_only)

  @reported_files = files.map(&:relative_path)

  do_comment(files) unless files.empty?
end