Sha256: 974c63f65520bf0bebba4bdf4d65b14a908a3697366d448711bd0b2708790927
Contents?: true
Size: 991 Bytes
Versions: 3
Compression:
Stored size: 991 Bytes
Contents
module Danger class SwiftFormat def initialize(path = nil) @path = path || "swiftformat" end def installed? Cmd.run([@path, "--version"]) end def check_format(files) output = Cmd.run([@path] + files + %w(--dryrun --verbose)) 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
danger-swiftformat-0.0.3 | lib/swiftformat/swiftformat.rb |
danger-swiftformat-0.0.2 | lib/swiftformat/swiftformat.rb |
danger-swiftformat-0.0.1 | lib/swiftformat/swiftformat.rb |