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

SwiftLint does not recognise the file path correctly #641

Open
taise-hikawa opened this issue Feb 1, 2025 · 2 comments
Open

SwiftLint does not recognise the file path correctly #641

taise-hikawa opened this issue Feb 1, 2025 · 2 comments

Comments

@taise-hikawa
Copy link

environment

mac os: 15.2
version: 3.21.1

description

I encountered an issue where, if the Dangerfile is not located in the root directory, SwiftLint does not correctly recognize the file paths. After reviewing the library's code, it seems there is no option to change the working directory for executing the SwiftLint command.

steps to reproduce

example: https://github.com/taise-hikawa/danger-sample
if you add SwiftLint.lint(inline: true, configFile: "../.swiftlint.yml") to Dangerfile.swift and try following command at ./LocalPackage directory, you can get following error messages.
swift run danger-swift pr https://github.com/taise-hikawa/danger-sample/pull/2 --verbose

error messages

Could not read contents of `/Users/hikawataisei/Desktop/code/private/danger-sample/LocalPackage/LocalPackage/Dangerfile.swift`
Could not read contents of `/Users/hikawataisei/Desktop/code/private/danger-sample/LocalPackage/LocalPackage/Package.swift`
Could not read contents of `/Users/hikawataisei/Desktop/code/private/danger-sample/LocalPackage/LocalPackage/Sources/DangerTarget/Fake.swift`
Could not read contents of `/Users/hikawataisei/Desktop/code/private/danger-sample/LocalPackage/LocalPackage/Sources/Hoge/HogeView.swift`
Could not read contents of `/Users/hikawataisei/Desktop/code/private/danger-sample/LocalPackage/danger-sample/DangerSampleApp.swift`

It appears this might be a bug in the Danger library. Could you please look into this? Let me know if you need any further details.
Thank you for your time and help.

@Arafo
Copy link

Arafo commented Feb 20, 2025

I got a similar issue on my end trying to run danger from a different directory like this:

DEBUG="*" swift run danger-swift ci --dangerfile ../../../Dangerfile.swift

It seems danger dsl is getting the modified paths without taking into account I'm running danger from another directory, I ended up correcting the files paths myself like this:

    let rootFolderPath = "../../.."
    let files = (danger.git.createdFiles + danger.git.modifiedFiles)
        .compactMap { "\(rootFolderPath)/\($0)" }
    SwiftLint.lint(
        .files(files),
        configFile: "\(rootFolderPath)/.swiftlint.yml",
        strict: true,
        swiftlintPath: .bin("\(rootFolderPath)/utils/swiftlint/swiftlint")
    )

@taise-hikawa
Copy link
Author

@Arafo
thanks!!
I also solved this problem with the workaround using .file!

I think it would be ideal to have a solution without needing a workaround, so I'll keep this issue open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants