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

Run rubocop with bundle exec #618

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
fix tool
  • Loading branch information
DMarinhoCodacy committed Jul 1, 2024
commit c0fcc031a19fafa3deb6b268f1af7a3fac3226e0
57 changes: 29 additions & 28 deletions src/main/scala/codacy/rubocop/Rubocop.scala
Original file line number Diff line number Diff line change
@@ -39,43 +39,44 @@ object Rubocop extends Tool {
private val filesToIgnore: Set[String] =
Set("Gemfile.lock").map(_.toLowerCase())

override def apply(
source: api.Source.Directory,
configuration: Option[List[Pattern.Definition]],
files: Option[Set[api.Source.File]],
options: Map[Options.Key, Options.Value]
)(implicit specification: Tool.Specification): Try[List[Result]] = {
val cmd = getCommandFor(Paths.get(source.path), configuration, files, specification, resultFilePath)
CommandRunner.exec(cmd, Some(new File(source.path))) match {
case Right(resultFromTool) =>
Try(parseResult(resultFilePath.toFile)).recover {
case e =>
val msg =
s"""
override def apply(
source: api.Source.Directory,
configuration: Option[List[Pattern.Definition]],
files: Option[Set[api.Source.File]],
options: Map[Options.Key, Options.Value]
)(implicit specification: Tool.Specification): Try[List[Result]] = {
val cmd = getCommandFor(Paths.get(source.path), configuration, files, specification, resultFilePath)
CommandRunner.exec(cmd, Some(new File(source.path))) match {
case Right(resultFromTool) =>
Try(parseResult(resultFilePath.toFile)).recover {
case e =>
val msg =
s"""
|Rubocop exited with code ${resultFromTool.exitCode}
|message: ${e.getMessage}
|stdout: ${resultFromTool.stdout.mkString(Properties.lineSeparator)}
|stderr: ${resultFromTool.stderr.mkString(Properties.lineSeparator)}
""".stripMargin
println(msg+resultFilePath)
List.empty[Result]
}
List.empty[Result]
}

case Left(e) =>
Failure(e)
case Left(e) =>
Failure(e)
}
}
}

private[this] def parseResult(filename: File): List[Result] = {
val resultFromTool = Source.fromFile(filename).getLines().mkString
val json = Json.parse(resultFromTool)
json.validate[RubocopResult] match {
case JsSuccess(rubocopResult, _) =>
rubocopResult.files.getOrElse(List.empty).flatMap(ruboFileToResult)
case JsError(_) =>
List.empty[Result] // Return an empty list in case of parsing errors
private[this] def parseResult(filename: File): List[Result] = {
val resultFromTool = Source.fromFile(filename).getLines().mkString
val json = Json.parse(resultFromTool)
json.validate[RubocopResult] match {
case JsSuccess(rubocopResult, _) =>
Success(rubocopResult.files.getOrElse(List.empty).flatMap { file =>
ruboFileToResult(file)
})
case JsError(_) =>
List.empty[Result] // Return an empty list in case of parsing errors
}
}
}

private[this] def ruboFileToResult(rubocopFiles: RubocopFiles): List[Result] = {
rubocopFiles.offenses.getOrElse(List.empty).map { offense =>