lib/swiftformat/swiftformat.rb in danger-swiftformat-0.7.0 vs lib/swiftformat/swiftformat.rb in danger-swiftformat-0.8.0
- old
+ new
@@ -8,14 +8,20 @@
def installed?
Cmd.run([@path, "--version"])
end
- def check_format(files, additional_args = "")
+ def check_format(files, additional_args = "", swiftversion = "")
cmd = [@path] + files
cmd << additional_args.split unless additional_args.nil? || additional_args.empty?
- cmd << %w(--dryrun --verbose)
+
+ unless swiftversion.empty?
+ cmd << "--swiftversion"
+ cmd << swiftversion
+ end
+
+ cmd << %w(--lint --lenient)
stdout, stderr, status = Cmd.run(cmd.flatten)
output = stdout.empty? ? stderr : stdout
raise "Error running SwiftFormat: Empty output." unless output
@@ -39,19 +45,19 @@
run_time: run_time(output)
}
}
end
- ERRORS_REGEX = /Formatting\s(.*)\n-- rules applied:(.*)$/.freeze
+ ERRORS_REGEX = /(.*:\d+:\d+): ((warning|error):.*)$/.freeze
def errors(output)
errors = []
output.scan(ERRORS_REGEX) do |match|
next if match.count < 2
errors << {
- file: match[0],
+ file: match[0].sub("#{Dir.pwd}/", ""),
rules: match[1].split(",").map(&:strip)
}
end
errors
end
@@ -60,10 +66,10 @@
def run_time(output)
if RUNTIME_REGEX.match(output)
RUNTIME_REGEX.match(output)[1]
else
- logger = Logger.new(STDERR)
+ logger = Logger.new($stderr)
logger.error("Invalid run_time output: #{output}")
"-1"
end
end
end