class Danger::DangerTailor
Shows the build errors, warnings and violations generated from Tailor
. You need [Tailor](tailor.sh) installed and generating a json file to use this plugin
@example Showing summary
tailor -f json MyProject/ > tailor.json danger-tailor.report 'tailor.json'
@example Filter out the pods before analyzing
danger-tailor.ignored_files = '**/Pods/**' danger-tailor.report 'tailor.json'
@see IntrepidPursuits/danger-tailor @tags xcode, swift, tailor, lint, format, xcodebuild
Attributes
A globbed string or array of strings which should match the files that you want to ignore warnings on. Defaults to nil. An example would be `'/Pods/'` to ignore warnings in Pods that your project uses.
@return [[String]] ignored-files
The project root, which will be used to make the paths relative. Defaults to `pwd`. @return [String] project_root
value
Defines if the test summary will be sticky or not. Defaults to `false`. @return [Boolean] sticky
Public Instance Methods
Reads a file with JSON Xcode summary and reports it.
@param [String] file_path Path for Tailor
summary in JSON format. @return [void]
# File lib/tailor/plugin.rb, line 56 def report(file_path) raise 'Summary file not found' unless File.file?(file_path) tailor_summary = JSON.parse(File.read(file_path), symbolize_names: true) run_summary(tailor_summary) end
Private Instance Methods
A method that returns a formatted string for a violation @return String
# File lib/tailor/plugin.rb, line 105 def format_violation(file_path, violation) "#{file_path}:#L#{violation[:location][:line]} -> #{violation[:rule]} - #{violation[:message]}" end
A method that takes the tailor summary, and for each file, parses out any violations found.
# File lib/tailor/plugin.rb, line 81 def parse_files(tailor_summary) tailor_summary[:files].each do |f| parse_violations(f[:path], f[:violations]) end end
A method that takes a file path, and an array of tailor violation objects, parses the violation, and calls the appropriate Danger
method
# File lib/tailor/plugin.rb, line 89 def parse_violations(file_path, violations) violations.each do |v| severity = v[:severity] message = format_violation(file_path, v) if severity == 'warning' warn(message, sticky: false) elsif severity == 'error' fail(message, sticky: false) end end end
# File lib/tailor/plugin.rb, line 64 def run_summary(tailor_summary) # Output the tailor summary message(summary_message(tailor_summary), sticky: sticky_summary) # Parse the file violations parse_files(tailor_summary) end
# File lib/tailor/plugin.rb, line 72 def summary_message(tailor_summary) summary = tailor_summary[:summary] m = "Tailor Summary: Analyzed #{summary[:analyzed]} files. Found #{summary[:violations]} violations. #{summary[:warnings]} Warnings and #{summary[:errors]} Errors." m << " Skipped #{summary[:skipped]} files." unless summary[:skipped].zero? m end