Skip to content

Commit

Permalink
Merge pull request #52 from thii/default-config-file
Browse files Browse the repository at this point in the history
Look for `.swiftlint.yml` file in project root if no config file was specified
  • Loading branch information
ashfurrow authored Aug 19, 2017
2 parents e76d24e + f1303e9 commit b749b09
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/danger_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit b749b09

Please sign in to comment.