diff --git a/lib/danger_plugin.rb b/lib/danger_plugin.rb index c9c9249..0941749 100755 --- a/lib/danger_plugin.rb +++ b/lib/danger_plugin.rb @@ -40,15 +40,23 @@ def lint_files(files=nil, inline_mode: false) # Fails if swiftlint isn't installed raise "swiftlint is not installed" unless swiftlint.is_installed? + config = if config_file + config_file + elsif File.file?('.swiftlint.yml') + '.swiftlint.yml' + else + nil + end + # Extract excluded paths - excluded_paths = excluded_files_from_config(config_file) + excluded_paths = excluded_files_from_config(config) # Extract swift files (ignoring excluded ones) files = find_swift_files(files, excluded_paths) # Prepare swiftlint options options = { - config: config_file, + config: config, reporter: 'json', quiet: true, pwd: directory || Dir.pwd @@ -120,7 +128,7 @@ def find_swift_files(files=nil, excluded_paths=[]) # @return [Array] list of files excluded def excluded_files_from_config(filepath) config = if filepath - YAML.load_file(config_file) + YAML.load_file(filepath) else {"excluded" => []} end @@ -129,7 +137,7 @@ def excluded_files_from_config(filepath) # Extract excluded paths return excluded_paths. - map { |path| File.join(File.dirname(config_file), path) }. + map { |path| File.join(File.dirname(filepath), path) }. map { |path| File.expand_path(path) }. select { |path| File.exists?(path) || Dir.exists?(path) } end