ashfurrow / danger-ruby-swiftlint

A Danger plugin for SwiftLint.
https://rubygems.org/gems/danger-swiftlint
MIT License
203 stars 80 forks source link

Source files that have been moved throw "error opening input file '/path/to/file' (No such file or directory)" #168

Closed rogerluan closed 3 years ago

rogerluan commented 3 years ago

Hey 👋

I've noticed that files that have been moved throw "No such file or directory" because this plugin attempts to read the file in its old location.

The errors thrown look like this:

error opening input file '/Users/rogerluan/Documents/Projects/redacted/redacted/SampleFile1.swift' (No such file or directory)
SourceKittenFramework/File.swift:28: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=260 "The file “SampleFile1.swift” couldn’t be opened because there is no such file." UserInfo={NSFilePath=/Users/rogerluan/Documents/Projects/redacted/redacted/SampleFile1.swift, NSUnderlyingError=0x7f858bc8d420 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

Not sure if this should be reported in Danger itself, or in this plugin, because I know for a fact that Danger itself report the moved files in a misleading way (IMO). We had to implement this workaround for other Dangerfiles in our project:

files_of_interest = git.added_files + git.modified_files
renamed_files = git.renamed_files
added_or_modified_files = files_of_interest.map do |file|
    renamed_dict = renamed_files.find { |dict| dict[:before] == file }
    if renamed_dict
        renamed_dict[:after]
    else
        file
    end
end

And whenever we want "added or modified files", we need to use added_or_modified_files instead of files_of_interest (in the example above).

How can we improve this behavior? Right now this plugin simply crashes when facing those errors 😬