Sha256: d7cd78e27a26fc34223b937451ca5330d7726d89a4917fa67ac01124da76661c
Contents?: true
Size: 1.09 KB
Versions: 2
Compression:
Stored size: 1.09 KB
Contents
module Danger class SwiftFormat def initialize(path = nil) @path = path || "swiftformat" end def installed? Cmd.run([@path, "--version"]) end def check_format(files, additional_args = "") cmd = [@path] + files cmd << additional_args.split unless additional_args.empty? cmd << %w(--dryrun --verbose) output = Cmd.run(cmd.flatten) raise "error running swiftformat: empty output" if output.empty? process(output) end private def process(output) { errors: errors(output), stats: { run_time: run_time(output) } } end ERRORS_REGEX = /rules applied:(.*)\n.*updated (.*)$/ def errors(output) errors = [] output.scan(ERRORS_REGEX) do |match| next if match.count < 2 errors << { file: match[1], rules: match[0].split(",").map(&:strip) } end errors end RUNTIME_REGEX = /.*swiftformat completed.*(.+\..+)s/ def run_time(output) RUNTIME_REGEX.match(output)[1] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
danger-swiftformat-0.2.0 | lib/swiftformat/swiftformat.rb |
danger-swiftformat-0.1.0 | lib/swiftformat/swiftformat.rb |