Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion docs/tests/scriptFile.scala

This file was deleted.

24 changes: 7 additions & 17 deletions src/main/scala/codacy/swiftlint/SwiftLint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package codacy.swiftlint
import java.nio.file.{Path, Paths}

import com.codacy.plugins.api.results.{Pattern, Result, Tool}
import com.codacy.plugins.api.{ErrorMessage, Options, Source}
import com.codacy.plugins.api.{Options, Source}
import com.codacy.tools.scala.seed.utils.{CommandRunner, FileHelper}
import com.codacy.tools.scala.seed.utils.ToolHelper._
import play.api.libs.json._
import better.files._
import com.codacy.plugins.api.results.Result.FileError

import scala.util.{Failure, Properties, Success, Try}

Expand Down Expand Up @@ -57,15 +56,16 @@ object SwiftLint extends Tool {
}
}

private def commandToRun(configOpt: Option[String], file: String): List[String] = {
private def commandToRun(configOpt: Option[String], files: List[String]): List[String] = {
val baseCmd = List("swiftlint", "lint", "--quiet", "--reporter", "json")

val configCmd = configOpt match {
case Some(opt) =>
baseCmd ++ List("--config", opt)
case None => baseCmd
}
configCmd :+ file

configCmd ++ files
}

private def runToolCommand(
Expand Down Expand Up @@ -102,24 +102,14 @@ object SwiftLint extends Tool {
options: Map[Options.Key, Options.Value]
)(implicit specification: Tool.Specification): Try[List[Result]] = {
Try {

val filesToLint = listOfFilesToLint(files, source)

val cfgOpt = configsFromCodacyConfiguration(configuration)

filesToLint.flatMap { file =>
val command: List[String] = commandToRun(cfgOpt, file)
val command: List[String] = commandToRun(cfgOpt, filesToLint)

val fileCommandAnalysisResult = runToolCommand(command, source, cfgOpt)
fileCommandAnalysisResult match {
case Success(res) => res
case Failure(exception) =>
List(
FileError(Source.File(file), Some(ErrorMessage(s"Failed to analyse file $file: ${exception.getMessage}")))
)
}
}
}
runToolCommand(command, source, cfgOpt)
}.flatten
Comment on lines +111 to +112

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 MEDIUM RISK

The move to batch execution removes the resilience provided by the previous per-file error handling. Previously, a crash or failure on a single file was captured as a FileError, allowing results for other files to still be reported. In the new batch mode, any failure during execution will cause the entire apply method to return a global Failure. While this trade-off is likely acceptable for the 100x performance gain, it changes how partial failures are communicated.

Try running the following prompt in your IDE agent:

Check if runToolCommand can be adapted to handle cases where SwiftLint returns a non-zero exit code but still produces partial JSON results on stdout, allowing us to report available violations even if the tool encountered an error on some files.

}

private def writeConfigFile(patternsToLint: List[Pattern.Definition]): Path = {
Expand Down