-
-
Notifications
You must be signed in to change notification settings - Fork 141
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
When no lintable files are found, serialization fails #231
Comments
How do you end up in this position? passing all modified files into the swiftlint api and it has no swift files? |
If there is a modified file, and you run swiftlint but that modified file is covered by the “excluded” section of the config, it seems to trigger this. |
I think is related to this change #180. EDIT: actually not because there is
Then yes is probably related to the excluded files as @thedavidharris was suggesting |
Looking at swiftlint code it looks exactly that https://github.com/realm/SwiftLint/blob/a97487f3e1540be97bbfef0d491f28302413d7c6/Source/swiftlint/Extensions/Configuration%2BCommandLine.swift |
fileprivate func getFiles(with visitor: LintableFilesVisitor) -> Result<[File], CommandantError<()>> {
if visitor.useSTDIN {
let stdinData = FileHandle.standardInput.readDataToEndOfFile()
if let stdinString = String(data: stdinData, encoding: .utf8) {
return .success([File(contents: stdinString)])
}
return .failure(.usageError(description: "stdin isn't a UTF8-encoded string"))
} else if visitor.useScriptInputFiles {
return scriptInputFiles()
.map { files in
guard visitor.forceExclude else {
return files
}
let scriptInputPaths = files.compactMap { $0.path }
return filterExcludedPaths(in: scriptInputPaths)
.map(File.init(pathDeferringReading:))
}
}
if !visitor.quiet {
let filesInfo: String
if visitor.paths.isEmpty {
filesInfo = "in current working directory"
} else {
filesInfo = "at paths \(visitor.paths.joined(separator: ", "))"
}
queuedPrintError("\(visitor.action) Swift files \(filesInfo)")
}
return .success(visitor.paths.flatMap {
self.lintableFiles(inPath: $0, forceExclude: visitor.forceExclude)
})
} if files.isEmpty {
let errorMessage = "No lintable files found at paths: '\(visitor.paths.joined(separator: ", "))'"
return .failure(.usageError(description: errorMessage))
} |
We could naively just look for |
PRs are always welcome :) |
I did find a solution, but I'm not happy with it... Avoid to read the stderror works, but means that if swiftlint fails we just ignore it |
Feels like there's a good longer term solution of importing the SwiftLint framework directly instead of depending on stdin/stdout. I feel like on the Swiftlint side that shouldn't go to stderr though... if you pass ignored files it should just send back an empty success? Not like there are any linting violations |
I agree, I think is like that because their use case is probably a little bit different (is meant to be used on the shell build task). |
Ah true, forgot it's not bundled with it here. Cursory look through swiftlint looks like it only outputs to stderr if the linting scenario is invalid, which should be guarded by this wrapper right? |
Yeah looked through the SwiftLint source a bit more, and the stderr outputs seem to only occur on usage errors; unfortunately, all of them are typically reasons to actually fail (like bad flags, etc.) except for this one, where the only changes are in the ignored files |
That is today, we can not make assumption on what they use the standard error for. |
True. Definitely better than the alternative, but it doesn't capture what should be the correct scenario here which is that when you only change files in the .swiftlint.yml's ignored section, Danger should pass without issue |
You are right, the thing is more that we can not know what is going on on swiftlint, best thing for us would be fix it on swiftlint itself |
Conveniently: realm/SwiftLint#2608 |
@thedavidharris @f-meloni did you ever figure out a workaround (without having to change swiftlint directly)? I don't believe I can even put a fix into my dangerfile to look for that error message and ignore it right? I can check the output of lint but and post an additional message, but I believe swiftlint will still fail the step right? |
@ecerney sorry for the really big delay, I totally missed your message, I believe this issue is been fixed on realm/SwiftLint#2732 |
That's correct, just noticing this as well, so I'll close it |
The output when the only changed files are ignored by the SwiftLint config seems to be:
No lintable files found at paths: ''
which then fails linting.
Should we just try and catch that message directly before serializing?
Output from the messaging is:
The text was updated successfully, but these errors were encountered: