Class: Danger::SwiftFormat
- Inherits:
-
Object
- Object
- Danger::SwiftFormat
- Defined in:
- lib/swiftformat/swiftformat.rb
Instance Method Summary collapse
- #check_format(files, additional_args = "", swiftversion = "") ⇒ Object
-
#initialize(path = nil) ⇒ SwiftFormat
constructor
A new instance of SwiftFormat.
- #installed? ⇒ Boolean
Constructor Details
#initialize(path = nil) ⇒ SwiftFormat
Returns a new instance of SwiftFormat.
5 6 7 |
# File 'lib/swiftformat/swiftformat.rb', line 5 def initialize(path = nil) @path = path || "swiftformat" end |
Instance Method Details
#check_format(files, additional_args = "", swiftversion = "") ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/swiftformat/swiftformat.rb', line 13 def check_format(files, additional_args = "", swiftversion = "") cmd = [@path] + files cmd << additional_args.split unless additional_args.nil? || additional_args.empty? unless swiftversion.nil? || 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 output = output.strip.no_color if status && !status.success? raise "Error running SwiftFormat:\nError: #{output}" else raise "Error running SwiftFormat: Empty output." if output.empty? end process(output) end |