Sha256: ca56e2e7029809944244595bac2c5799da549bb0ef2cf3229e4c416c6d4e1d05

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Danger
  require "open3"

  # Run swift-format.
  # This is using https://github.com/apple/swift-format
  #
  # @example Run swift-format format
  #          swift_format.binary_path = ".build/x86_64-apple-macosx/release/swift-format"
  #          swift_format.configuration = "swift-format.json"
  #          swift_format.format("Sources/*.swift", true)
  #
  # @see  marumemomo/danger-swift_format
  # @tags swift-format
  #

  class DangerSwiftFormat < Plugin

    # swift-format configuration file path
    #
    # @return   [Array<String>]
    attr_accessor :configuration

    # swift-format binary path
    #
    # @return   [Array<String>]
    attr_accessor :binary_path

    # run swift-format lint
    # @return   [Array<String>]
    #
    def lint(files)
      o, e, s = Open3.capture3("#{binary_path} lint -r --configuration #{configuration} #{files}")
      return if e == ''
      warn e
    end

    # run swift-format format
    # @return   [Array<String>]
    #
    def format(files, in_place = false)
      in_place_option = "-i"
      in_place_option = '' if !in_place
      o, e, s = Open3.capture3("#{binary_path} format -r #{in_place_option} --configuration #{configuration} #{files}")
      return if e == ''
      warn e
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
danger-apple_swift_format-0.0.2 lib/swift_format/plugin.rb