Act on Option2Iterable wart (#5154)

Some Option2Iterable ignore annotations are not needed, others were needed for unused methods.

In a few occasions we were ignoring the warning for the very purpose for which is was there,
i.e. avoiding an implicit conversion. I'm all for not verifying this rule if we agree we
don't need it.

For ProcessFailedException it was a bit gratuitous, I changed the way in which the exception
message is built.

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
Stefano Baghino 2020-03-24 12:25:05 +01:00 committed by GitHub
parent 4095538acf
commit 181df8f3ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 36 additions and 77 deletions

View File

@ -26,7 +26,6 @@ import scala.collection.JavaConverters._
* method it's overloading, meaning that the return type will be
* boxed even if it's a DAML-LF primitive
*/
@SuppressWarnings(Array("org.wartremover.warts.Option2Iterable"))
object ToValueGenerator {
import Types._

View File

@ -64,7 +64,6 @@ final class ApiTransactionService private (
private val subscriptionIdCounter = new AtomicLong()
@SuppressWarnings(Array("org.wartremover.warts.Option2Iterable"))
override def getTransactions(
request: GetTransactionsRequest): Source[GetTransactionsResponse, NotUsed] =
withEnrichedLoggingContext(

View File

@ -38,7 +38,6 @@ import scala.concurrent.Future
@SuppressWarnings(
Array(
"org.wartremover.warts.Any",
"org.wartremover.warts.Option2Iterable",
"org.wartremover.warts.StringPlusAny"
))
abstract class ScenarioLoadingITBase

View File

@ -21,7 +21,6 @@ import org.scalatest.{Matchers, WordSpec}
@SuppressWarnings(
Array(
"org.wartremover.warts.Any",
"org.wartremover.warts.Option2Iterable",
"org.wartremover.warts.StringPlusAny"
))
class ScenarioLoadingITDivulgence

View File

@ -163,11 +163,11 @@ trait PostgresAround {
IOUtils.copy(process.getErrorStream, stderr, StandardCharsets.UTF_8)
val logs = Files.readAllLines(postgresFixture.logFile).asScala
throw new ProcessFailedException(
description,
command,
Some(stdout.toString),
Some(stderr.toString),
logs,
description = description,
command = command,
stdout = stdout.toString,
stderr = stderr.toString,
logs = logs,
)
}
} catch {
@ -175,7 +175,12 @@ trait PostgresAround {
throw e
case NonFatal(e) =>
val logs = Files.readAllLines(postgresFixture.logFile).asScala
throw new ProcessFailedException(description, command, None, None, logs, e)
throw new ProcessFailedException(
description = description,
command = command,
logs = logs,
cause = e,
)
}
}
@ -190,31 +195,22 @@ object PostgresAround {
private val userName = "test"
private val databaseName = "test"
@SuppressWarnings(Array("org.wartremover.warts.Option2Iterable"))
private class ProcessFailedException(
description: String,
command: Seq[String],
stdout: Option[String],
stderr: Option[String],
logs: Seq[String],
cause: Throwable,
stdout: String = "<none>",
stderr: String = "<none>",
logs: Seq[String] = Seq.empty,
cause: Throwable = null,
) extends RuntimeException(
Seq(
Some(s"Failed to $description."),
Some(s"Command:"),
Some(command.mkString("\n")),
stdout.map(output => s"\nSTDOUT:\n$output"),
stderr.map(output => s"\nSTDERR:\n$output"),
Some(logs).filter(_.nonEmpty).map(lines => s"\nLogs:\n${lines.mkString("\n")}"),
).flatten.mkString("\n"),
s"Failed to $description.",
s"Command:",
command.mkString("\n"),
s"\nSTDOUT:\n$stdout",
s"\nSTDERR:\n$stderr",
logs.map(lines => s"\nLogs:\n${lines.mkString("\n")}"),
).mkString("\n"),
cause,
) {
def this(
description: String,
command: Seq[String],
stdout: Option[String],
stderr: Option[String],
logs: Seq[String],
) = this(description, command, stdout, stderr, logs, null)
}
)
}

View File

@ -44,7 +44,7 @@ import scala.util.{Failure, Success, Try}
* A new UI backend can be implemented by extending [[UIBackend]] and by providing
* the [[customEndpoints]], [[customRoutes]], [[applicationInfo]] definitions.
*/
@SuppressWarnings(Array("org.wartremover.warts.Any", "org.wartremover.warts.Option2Iterable"))
@SuppressWarnings(Array("org.wartremover.warts.Any"))
abstract class UIBackend extends LazyLogging with ApplicationInfoJsonSupport {
def customEndpoints: Set[CustomEndpoint[_]]
@ -78,7 +78,8 @@ abstract class UIBackend extends LazyLogging with ApplicationInfoJsonSupport {
case Cookie(cookies) =>
cookies
.filter(_.name == "session-id")
.flatMap(cookiePair => Session.current(cookiePair.value).map(cookiePair.value -> _))
.flatMap(cookiePair =>
Session.current(cookiePair.value).map(cookiePair.value -> _).toList)
.headOption
case _ =>
None

View File

@ -22,12 +22,11 @@ import scalaz.Tag
final case class UserConfig(password: Option[String], party: PartyState, role: Option[String])
/* The configuration has an empty map as default list of users because you can login as party too */
@SuppressWarnings(Array("org.wartremover.warts.Option2Iterable"))
final case class Config(users: Map[String, UserConfig] = Map.empty[String, UserConfig]) {
def userIds: Set[String] = users.keySet
def roles: Set[String] = users.values.flatMap(_.role)(collection.breakOut)
def roles: Set[String] = users.values.flatMap(_.role.toList)(collection.breakOut)
def parties: Set[PartyState] = users.values.map(_.party)(collection.breakOut)
}
@ -45,7 +44,7 @@ sealed abstract class ConfigOption {
final case class DefaultConfig(path: Path) extends ConfigOption
final case class ExplicitConfig(path: Path) extends ConfigOption
@SuppressWarnings(Array("org.wartremover.warts.Any", "org.wartremover.warts.Option2Iterable"))
@SuppressWarnings(Array("org.wartremover.warts.Any"))
object Config {
private[this] val logger = LoggerFactory.getLogger(this.getClass)

View File

@ -71,8 +71,7 @@ object Maths {
* &lt;- 7 ->
* </pre>
*/
@SuppressWarnings(
Array("org.wartremover.warts.Option2Iterable", "org.wartremover.warts.StringPlusAny"))
@SuppressWarnings(Array("org.wartremover.warts.StringPlusAny"))
final class AsciiTable {
private var header: Option[Seq[String]] = None
private val streamBuilder = new StreamBuilder[Seq[String]]

View File

@ -19,11 +19,7 @@ import scala.concurrent.{Await, ExecutionContext, Future}
import scala.concurrent.duration._
import scala.util.Try
@SuppressWarnings(
Array(
"org.wartremover.warts.Product",
"org.wartremover.warts.Option2Iterable",
"org.wartremover.warts.Serializable"))
@SuppressWarnings(Array("org.wartremover.warts.Product", "org.wartremover.warts.Serializable"))
case object Exercise extends SimpleCommand {
def name: String = "exercise"

View File

@ -6,7 +6,6 @@ package com.digitalasset.navigator.console.commands
import java.util.concurrent.TimeUnit
import com.digitalasset.ledger.api.refinements.ApiTypes
import com.digitalasset.ledger.api.tls.TlsConfiguration
import com.digitalasset.navigator.console._
import com.digitalasset.navigator.store.Store._
import com.digitalasset.navigator.time.TimeProviderType
@ -17,7 +16,6 @@ import scala.concurrent.Await
import scala.concurrent.duration._
import scala.util.Try
@SuppressWarnings(Array("org.wartremover.warts.Option2Iterable"))
case object Info extends SimpleCommand {
def name: String = "info"
@ -114,19 +112,6 @@ case object Info extends SimpleCommand {
} yield (state, getBanner(state) + "\n" + Pretty.yaml(prettyInfo(info, state)))
}
private def tlsInfo(info: Option[TlsConfiguration]): String = {
info
.map(c =>
if (c.enabled) {
val crt = c.keyCertChainFile.map(_ => "CRT")
val pem = c.keyFile.map(_ => "PEM")
val cacrt = c.trustCertCollectionFile.map(_ => "CACRT")
val options = List(crt, pem, cacrt).flatten
s"Enabled, using ${options.mkString(", ")}."
} else "Disabled.")
.getOrElse("Not set.")
}
def getBanner(state: State): String = {
s"Navigator version: ${state.applicationInfo.version}"
}

View File

@ -41,11 +41,7 @@ case class UserFacingError(message: String)
}
/** Schema definition for the UI backend GraphQL API. */
@SuppressWarnings(
Array(
"org.wartremover.warts.Any",
"org.wartremover.warts.Option2Iterable",
"org.wartremover.warts.JavaSerializable"))
@SuppressWarnings(Array("org.wartremover.warts.Any", "org.wartremover.warts.JavaSerializable"))
final class GraphQLSchema(customEndpoints: Set[CustomEndpoint[_]]) {
implicit private val actorTimeout: Timeout = Timeout(60, TimeUnit.SECONDS)
@ -586,27 +582,27 @@ final class GraphQLSchema(customEndpoints: Set[CustomEndpoint[_]]) {
case ContractType.name =>
ids
.map(id => ApiTypes.ContractId(id.toString))
.flatMap(ledger.contract(_, context.ctx.templates))
.flatMap(ledger.contract(_, context.ctx.templates).toList)
.toSeq
case TemplateType.name =>
ids
.map(id => TemplateStringId(id.toString))
.flatMap(context.ctx.templates.templateByStringId)
.flatMap(context.ctx.templates.templateByStringId(_).toList)
.toSeq
case CommandType.name =>
ids
.map(id => ApiTypes.CommandId(id.toString))
.flatMap(context.ctx.ledger.command(_, context.ctx.templates))
.flatMap(context.ctx.ledger.command(_, context.ctx.templates).toList)
.toSeq
case EventType.name =>
ids
.map(id => ApiTypes.EventId(id.toString))
.flatMap(context.ctx.ledger.event(_, context.ctx.templates))
.flatMap(context.ctx.ledger.event(_, context.ctx.templates).toList)
.toSeq
case TransactionType.name =>
ids
.map(id => ApiTypes.TransactionId(id.toString))
.flatMap(context.ctx.ledger.transaction(_, context.ctx.templates))
.flatMap(context.ctx.ledger.transaction(_, context.ctx.templates).toList)
.toSeq
case _ => Seq.empty[Node[_]]
}

View File

@ -10,7 +10,6 @@ import com.typesafe.scalalogging.LazyLogging
import scala.util.{Failure, Success, Try}
/** In-memory projection of ledger events. */
@SuppressWarnings(Array("org.wartremover.warts.Option2Iterable"))
case class Ledger(
private val forParty: ApiTypes.Party,
private val lastTransaction: Option[Transaction],
@ -178,14 +177,6 @@ case class Ledger(
}
}
private def contractsByTemplateIdWithout(contractId: ApiTypes.ContractId) = {
val entryWithoutContract = for {
contract <- contractById.get(contractId)
templateContracts <- contractsByTemplateId.get(contract.template.id)
} yield contract.template.id -> (templateContracts - contract)
contractsByTemplateId ++ entryWithoutContract.toMap
}
def allContractsCount: Int = {
if (useDatabase) {
logErrorAndDefaultTo(db.contractCount(), 0)