Skip to content

Commit 161c45f

Browse files
authored
bump: Update case-app to 2.1.0-M14 and Scala to 2.13 (#493)
* bump: Update case-app to 2.0.0 * Update case-app to 2.1.0-M10 * Update to case-app 2.1.0-M11 * Update case-app to 2.1.0-M14 * style: Run scalafmt * bump: Update Scala to 2.13.13
1 parent 9b03779 commit 161c45f

File tree

10 files changed

+56
-39
lines changed

10 files changed

+56
-39
lines changed

api-scala/src/main/scala/com/codacy/api/CoverageReport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object CoverageReport {
1010
implicit val mapWrites: Writes[Map[Int, Int]] = Writes[Map[Int, Int]] { map: Map[Int, Int] =>
1111
JsObject(map.map {
1212
case (key, value) => (key.toString, JsNumber(value))
13-
}(collection.breakOut))
13+
})
1414
}
1515
implicit val coverageFileReportWrites: Writes[CoverageFileReport] = Json.writes[CoverageFileReport]
1616
implicit val coverageReportWrites: Writes[CoverageReport] = Json.writes[CoverageReport]

api-scala/src/main/scala/com/codacy/api/util/JsonOps.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package com.codacy.api.util
22

33
import play.api.libs.json.{JsError, JsPath, Json, JsonValidationError}
44

5+
import scala.collection
6+
57
object JsonOps {
68

7-
def handleConversionFailure(error: Seq[(JsPath, Seq[JsonValidationError])]): String = {
9+
def handleConversionFailure(error: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]): String = {
810
val jsonError = Json.stringify(JsError.toJson(error.toList))
911
s"Json conversion error: $jsonError"
1012
}

build.sbt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
inThisBuild(
22
Seq(
3-
scalaVersion := "2.12.18",
4-
scalacOptions := Seq(
5-
"-deprecation",
6-
"-feature",
7-
"-unchecked",
8-
"-Ywarn-adapted-args",
9-
"-Xlint",
10-
"-Xfatal-warnings",
11-
"-Ypartial-unification"
12-
)
3+
scalaVersion := "2.13.13",
4+
scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Xlint", "-Xfatal-warnings")
135
)
146
)
157

168
name := "codacy-coverage-reporter"
179

1810
// Runtime dependencies
1911
libraryDependencies ++= Seq(
20-
"com.github.alexarchambault" %% "case-app" % "1.2.0",
12+
"com.github.alexarchambault" %% "case-app" % "2.1.0-M14",
2113
"org.wvlet.airframe" %% "airframe-log" % "22.3.0",
2214
"com.lihaoyi" %% "ujson" % "1.5.0"
2315
)

coverage-parser/src/main/scala/com/codacy/parsers/implementation/CoberturaParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object CoberturaParser extends CoverageParser with XmlReportParser {
3737
} yield {
3838
val cleanFilename = TextUtils.sanitiseFilename(filename).stripPrefix(projectRootStr).stripPrefix("/")
3939
lineCoverage(cleanFilename, classes)
40-
})(collection.breakOut)
40+
}).toList
4141

4242
CoverageReport(fileReports)
4343
}

coverage-parser/src/main/scala/com/codacy/parsers/implementation/JacocoParser.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ object JacocoParser extends CoverageParser with XmlReportParser {
4242
}
4343

4444
private def lineCoverage(filename: String, fileNode: Node): CoverageFileReport = {
45-
val lineHitMap: Map[Int, Int] = (fileNode \\ "line")
45+
val lineHitMap: Map[Int, Int] = (fileNode \\ "line").view
4646
.map { line =>
4747
(line \@ "nr").toInt -> LineCoverage((line \@ "mi").toInt, (line \@ "ci").toInt)
4848
}
4949
.collect {
5050
case (key, lineCoverage) if lineCoverage.missedInstructions + lineCoverage.coveredInstructions > 0 =>
5151
key -> (if (lineCoverage.coveredInstructions > 0) 1 else 0)
52-
}(collection.breakOut)
52+
}
53+
.toMap
5354

5455
CoverageFileReport(filename, lineHitMap)
5556
}

coverage-parser/src/main/scala/com/codacy/parsers/implementation/PhpUnitXmlParser.scala

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,22 @@ object PhpUnitXmlParser extends CoverageParser with XmlReportParser {
4444
reportRootPath: String
4545
): Either[String, Seq[CoverageFileReport]] = {
4646
val builder = Seq.newBuilder[CoverageFileReport]
47-
for (f <- fileNodes) {
47+
var error = Option.empty[String]
48+
for (f <- fileNodes if error.isEmpty) {
4849
val reportFileName = f \@ "href"
4950
val fileName = getSourceFileName(projectRootPath, codeDirectory, reportFileName)
5051
getLineCoverage(reportRootPath, reportFileName) match {
5152
case Right(lineCoverage) =>
5253
builder += CoverageFileReport(fileName, lineCoverage)
53-
case Left(message) => return Left(message)
54+
case Left(message) => error = Some(message)
5455
}
5556
}
56-
Right(builder.result())
57+
error match {
58+
case Some(value) =>
59+
Left(value)
60+
case None =>
61+
Right(builder.result())
62+
}
5763
}
5864

5965
private def getLineCoverage(reportRootPath: String, filename: String) = {

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "25.1.1")
55
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.4")
66

77
// Coverage
8-
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
8+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
99

1010
libraryDependencySchemes ++= Seq("org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always)

src/main/scala/com/codacy/configuration/parser/ConfigurationParser.scala

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package com.codacy.configuration.parser
22

33
import java.io.File
44
import caseapp._
5-
import caseapp.core.ArgParser
5+
import caseapp.core.Error
6+
import caseapp.core.app._
7+
import caseapp.core.argparser.ArgParser
68
import com.codacy.api.OrganizationProvider
79
import com.codacy.configuration.parser.ConfigArgumentParsers._
810
import com.codacy.parsers.CoverageParser
@@ -108,7 +110,10 @@ case class BaseCommandConfig(
108110

109111
object ConfigArgumentParsers {
110112

111-
implicit val fileParser: ArgParser[File] = ArgParser.instance("file")(a => Right(new File(a)))
113+
implicit val fileParser: ArgParser[File] = new ArgParser[File] {
114+
def apply(current: Option[File], index: Int, span: Int, value: String) = Right(new File(value))
115+
def description = "file"
116+
}
112117

113118
val parsersMap = Map(
114119
"cobertura" -> CoberturaParser,
@@ -121,27 +126,38 @@ object ConfigArgumentParsers {
121126
"go" -> GoParser
122127
)
123128

124-
implicit val coverageParser: ArgParser[CoverageParser] = ArgParser.instance("parser") { v =>
125-
val value = v.trim.toLowerCase
126-
parsersMap.get(value) match {
127-
case Some(parser) => Right(parser)
128-
case _ =>
129-
Left(
130-
s"${value} is an unsupported/unrecognized coverage parser. (Available patterns are: ${parsersMap.keys.mkString(",")})"
131-
)
129+
implicit val coverageParser: ArgParser[CoverageParser] = new ArgParser[CoverageParser] {
130+
131+
def apply(current: Option[CoverageParser], index: Int, span: Int, v: String) = {
132+
val value = v.trim.toLowerCase
133+
parsersMap.get(value) match {
134+
case Some(parser) => Right(parser)
135+
case _ =>
136+
Left(
137+
Error.Other(
138+
s"${value} is an unsupported/unrecognized coverage parser. (Available patterns are: ${parsersMap.keys.mkString(",")})"
139+
)
140+
)
141+
}
132142
}
143+
def description = "parser"
133144
}
134145

135-
implicit val organizationProvider: ArgParser[OrganizationProvider.Value] =
136-
ArgParser.instance("organizationProvider") { v =>
146+
implicit val organizationProvider: ArgParser[OrganizationProvider.Value] = new ArgParser[OrganizationProvider.Value] {
147+
148+
def apply(current: Option[OrganizationProvider.Value], index: Int, span: Int, v: String) = {
137149
val value = v.trim.toLowerCase
138150
OrganizationProvider.values.find(_.toString == value) match {
139151
case Some(provider) => Right(provider)
140152
case _ =>
141153
Left(
142-
s"${value} is an unsupported/unrecognized organization provider. (Available organization provider are: ${OrganizationProvider.values
143-
.mkString(",")})"
154+
Error.Other(
155+
s"${value} is an unsupported/unrecognized organization provider. (Available organization provider are: ${OrganizationProvider.values
156+
.mkString(",")})"
157+
)
144158
)
145159
}
146160
}
161+
def description = "organizationProvider"
162+
}
147163
}

src/main/scala/com/codacy/rules/ConfigurationRules.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,9 @@ class ConfigurationRules(cmdConfig: CommandConfiguration, envVars: Map[String, S
187187
*/
188188
private[rules] def validateReportFiles(filesOpt: Option[List[File]]): Either[String, List[File]] = {
189189
filesOpt match {
190-
case Some(value) if value.isEmpty =>
190+
case Some(Nil) =>
191191
Left("Invalid report list. Try passing a report file with -r")
192-
case Some(value) if value.nonEmpty =>
192+
case Some(value) =>
193193
Right(value)
194194
case None =>
195195
Right(List.empty[File])

src/main/scala/com/codacy/rules/ReportRules.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,17 @@ class ReportRules(coverageServices: => CoverageServices, gitFileFetcher: GitFile
209209
val reportLanguages = getReportLanguages(report).distinct
210210
reportLanguages.headOption match {
211211
case None => Left("Can't guess the report language")
212-
case Some(language) =>
212+
case Some(l) =>
213213
if (reportLanguages.size > 1) {
214214
logger.warn(
215215
s"""
216216
|Multiple languages detected in $reportFilePath (${reportLanguages.mkString(",")}).
217-
| This run will only upload coverage for the $language language.
217+
| This run will only upload coverage for the $l language.
218218
| To make sure that you upload coverage for all languages in the report,
219219
| see https://docs.codacy.com/coverage-reporter/uploading-coverage-in-advanced-scenarios/#multiple-languages""".stripMargin
220220
)
221221
}
222-
Right(language)
222+
Right(l)
223223
}
224224
}
225225
}

0 commit comments

Comments
 (0)