Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Look for .swiftlint.yml file in project root if no config file was specified #52

Merged
merged 1 commit into from
Aug 19, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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