Skip to content

Commit

Permalink
Merge pull request #161 from dirtyhabits97/task/improve-config
Browse files Browse the repository at this point in the history
Improved `config-file` handling to match SwiftLint's expected behavior.
  • Loading branch information
ashfurrow committed Mar 31, 2021
2 parents 92cf9a9 + 516111d commit 36ca334
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
18 changes: 9 additions & 9 deletions lib/danger_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class DangerSwiftlint < Plugin

# Errors found
attr_accessor :errors

# All issues found
attr_accessor :issues

Expand All @@ -67,12 +67,12 @@ def lint_files(files = nil, inline_mode: false, fail_on_error: false, additional
# Fails if swiftlint isn't installed
raise 'swiftlint is not installed' unless swiftlint.installed?

config_file_path = if config_file
config_file
elsif !lint_all_files && File.file?('.swiftlint.yml')
File.expand_path('.swiftlint.yml')
end
log "Using config file: #{config_file_path}"
config_file_path = config_file
if config_file_path
log "Using config file: #{config_file_path}"
else
log 'Config file was not specified.'
end

dir_selected = directory ? File.expand_path(directory) : Dir.pwd
log "Swiftlint will be run from #{dir_selected}"
Expand Down Expand Up @@ -124,7 +124,7 @@ def lint_files(files = nil, inline_mode: false, fail_on_error: false, additional
issues = issues.take(@max_num_violations)
end
log "Received from Swiftlint: #{issues}"

# filter out any unwanted violations with the passed in select_block
if select_block && !no_comment
issues = issues.select { |issue| select_block.call(issue) }
Expand All @@ -133,7 +133,7 @@ def lint_files(files = nil, inline_mode: false, fail_on_error: false, additional
# Filter warnings and errors
@warnings = issues.select { |issue| issue['severity'] == 'Warning' }
@errors = issues.select { |issue| issue['severity'] == 'Error' }

# Early exit so we don't comment
return if no_comment

Expand Down
18 changes: 0 additions & 18 deletions spec/danger_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,24 +314,6 @@ module Danger
@swiftlint.lint_files
end

it 'expands default config file (if present) to absolute path' do
allow(@swiftlint.git).to receive(:added_files).and_return([])
allow(@swiftlint.git).to receive(:modified_files).and_return([
'spec/fixtures/SwiftFile.swift'
])
expect(File).to receive(:file?).and_return(true)
expect(File).to receive(:exist?).and_return(true)
expect(File).to receive(:open).and_return(StringIO.new)
expect(YAML).to receive(:safe_load).and_return({})

expect_any_instance_of(Swiftlint).to receive(:lint)
.with(hash_including(config: File.expand_path('.swiftlint.yml')), '', anything)
.once
.and_return(@swiftlint_response)

@swiftlint.lint_files
end

it 'expands specified config file to absolute path' do
allow(@swiftlint.git).to receive(:added_files).and_return([])
allow(@swiftlint.git).to receive(:modified_files).and_return([
Expand Down

0 comments on commit 36ca334

Please sign in to comment.