ext/swiftlint/swiftlint.rb in danger-swiftlint-0.10.1 vs ext/swiftlint/swiftlint.rb in danger-swiftlint-0.10.2

- old
+ new

@@ -1,17 +1,17 @@ +# frozen_string_literal: true +# A wrapper to use SwiftLint via a Ruby API. class Swiftlint - def initialize(swiftlint_path=nil) + def initialize(swiftlint_path = nil) @swiftlint_path = swiftlint_path end # Runs swiftlint - def run(cmd='lint', additional_swiftlint_args='', options={}) + def run(cmd = 'lint', additional_swiftlint_args = '', options = {}) # change pwd before run swiftlint - if options.has_key? :pwd - Dir.chdir options.delete(:pwd) - end + Dir.chdir options.delete(:pwd) if options.key? :pwd # run swiftlint with provided options `#{swiftlint_path} #{cmd} #{swiftlint_arguments(options, additional_swiftlint_args)}` end @@ -19,37 +19,37 @@ def lint(options, additional_swiftlint_args) run('lint', additional_swiftlint_args, options) end # Return true if swiftlint is installed or false otherwise - def is_installed? + def installed? File.exist?(swiftlint_path) end # Return swiftlint execution path def swiftlint_path - @swiftlint_path or default_swiftlint_path + @swiftlint_path || default_swiftlint_path end private # Parse options into shell arguments how swift expect it to be # more information: https://github.com/Carthage/Commandant # @param options (Hash) hash containing swiftlint options - def swiftlint_arguments (options, additional_swiftlint_args) + def swiftlint_arguments(options, additional_swiftlint_args) (options. # filter not null - select {|key, value| !value.nil?}. + reject { |_key, value| value.nil? }. # map booleans arguments equal true map { |key, value| value.is_a?(TrueClass) ? [key, ''] : [key, value] }. # map booleans arguments equal false map { |key, value| value.is_a?(FalseClass) ? ["no-#{key}", ''] : [key, value] }. # replace underscore by hyphen map { |key, value| [key.to_s.tr('_', '-'), value] }. # prepend '--' into the argument map { |key, value| ["--#{key}", value] }. # reduce everything into a single string - reduce('') { |args, option| "#{args} #{option[0]} #{option[1]}"} + + reduce('') { |args, option| "#{args} #{option[0]} #{option[1]}" } + " #{additional_swiftlint_args}"). # strip leading spaces strip end