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)

See Also:

  • Matsuda/danger-checkstyle_reports

Constant Summary collapse

REPORT_METHODS =
%i(message warn fail).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#inline_commentBoolean

Optional Create inline comment if true.

Returns:

  • (Boolean)

    true by default



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

def inline_comment
  @inline_comment
end

#min_severityString, Symbol

Optional minimum severity to be reported (inclusive)

Returns:

  • (String, Symbol)

    error by default



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

def min_severity
  @min_severity
end

#report_methodString, Symbol

Optional Set report method

Returns:

  • (String, Symbol)

    error by default



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

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



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

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.



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

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



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/checkstyle_reports/plugin.rb', line 69

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