From 5986497ee1e8fd7613b4b6b0cfd5f7126e6adacc Mon Sep 17 00:00:00 2001 From: Jamie B <53781962+JamieB-gu@users.noreply.github.com> Date: Tue, 23 Jul 2024 17:28:39 +0100 Subject: [PATCH] Added and ran scalafix with two rules (#197) Preparation for upgrading to Scala 2.13. This has added a number of type annotations. --- .scalafix.conf | 5 +++++ app/conf/Configuration.scala | 2 +- app/controllers/DefaultsController.scala | 3 ++- app/story_packages/metrics/CloudWatch.scala | 4 ++-- app/story_packages/metrics/metrics.scala | 2 +- app/story_packages/model/StoryPackage.scala | 7 ++++--- app/story_packages/model/frontsapi.scala | 2 +- app/story_packages/services/S3.scala | 4 ++-- app/story_packages/switchboard/Switchboard.scala | 2 +- app/story_packages/updates/KinesisEventSender.scala | 2 +- app/story_packages/updates/Reindex.scala | 3 ++- app/story_packages/updates/UpdateMessage.scala | 2 +- project/plugins.sbt | 2 ++ 13 files changed, 25 insertions(+), 15 deletions(-) create mode 100644 .scalafix.conf diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000..bcee716 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,5 @@ +rules = [ + ExplicitResultTypes, + ProcedureSyntax, +] +ExplicitResultTypes.onlyImplicits = true diff --git a/app/conf/Configuration.scala b/app/conf/Configuration.scala index d0e43cc..05971f5 100644 --- a/app/conf/Configuration.scala +++ b/app/conf/Configuration.scala @@ -185,7 +185,7 @@ object Properties extends AutomaticResourceManagement { } trait AutomaticResourceManagement { - def withCloseable[T <: { def close() }](closeable: T) = new { + def withCloseable[T <: { def close(): Unit }](closeable: T) = new { def apply[S](body: T => S) = try { body(closeable) } finally { diff --git a/app/controllers/DefaultsController.scala b/app/controllers/DefaultsController.scala index dcb7e90..b03502d 100644 --- a/app/controllers/DefaultsController.scala +++ b/app/controllers/DefaultsController.scala @@ -8,9 +8,10 @@ import conf.ApplicationConfiguration import play.api.Mode.Dev import play.api.libs.ws.WSClient import story_packages.switchboard.SwitchManager +import play.api.libs.json.OWrites object Defaults { - implicit val jsonFormat = Json.writes[Defaults] + implicit val jsonFormat: OWrites[Defaults] = Json.writes[Defaults] } case class Defaults( diff --git a/app/story_packages/metrics/CloudWatch.scala b/app/story_packages/metrics/CloudWatch.scala index 04f7dac..9d358b9 100644 --- a/app/story_packages/metrics/CloudWatch.scala +++ b/app/story_packages/metrics/CloudWatch.scala @@ -19,11 +19,11 @@ class CloudWatch(config: ApplicationConfiguration) extends Logging { } trait LoggingAsyncHandler extends AsyncHandler[PutMetricDataRequest, PutMetricDataResult] { - def onError(exception: Exception) + def onError(exception: Exception): Unit = { Logger.info(s"CloudWatch PutMetricDataRequest error: ${exception.getMessage}}") } - def onSuccess(request: PutMetricDataRequest, result: PutMetricDataResult ) + def onSuccess(request: PutMetricDataRequest, result: PutMetricDataResult ): Unit = { Logger.info("CloudWatch PutMetricDataRequest - success") } diff --git a/app/story_packages/metrics/metrics.scala b/app/story_packages/metrics/metrics.scala index c7968a7..96fe76e 100644 --- a/app/story_packages/metrics/metrics.scala +++ b/app/story_packages/metrics/metrics.scala @@ -202,7 +202,7 @@ class CloudWatchApplicationMetrics(appName: String, stage: String, cloudWatch: C ) )} - private def report() { + private def report(): Unit = { val allMetrics: List[FrontendMetric] = this.systemMetrics ::: this.applicationMetrics if (!isDev) { val stageDimension = new Dimension().withName("Stage").withValue(stage) diff --git a/app/story_packages/model/StoryPackage.scala b/app/story_packages/model/StoryPackage.scala index eb73818..0494da4 100644 --- a/app/story_packages/model/StoryPackage.scala +++ b/app/story_packages/model/StoryPackage.scala @@ -2,6 +2,7 @@ package story_packages.model import org.joda.time.{DateTime, DateTimeZone} import play.api.libs.json.Json +import play.api.libs.json.OFormat case class StoryPackage( id: Option[String], @@ -15,11 +16,11 @@ case class StoryPackage( deleted: Option[Boolean] ) {} object StoryPackage { - implicit val jsonFormat = Json.format[StoryPackage] + implicit val jsonFormat: OFormat[StoryPackage] = Json.format[StoryPackage] } object SortByLastModify { - implicit val sortByModifyDate = new Ordering[StoryPackage] { + implicit val sortByModifyDate: Ordering[StoryPackage] = new Ordering[StoryPackage] { def compare(a: StoryPackage, b: StoryPackage) = (a.lastModify, b.lastModify) match { case (None, None) => 0 case (Some(_), None) => -1 @@ -29,7 +30,7 @@ object SortByLastModify { } } object SortByName { - implicit val sortByModifyDate = new Ordering[StoryPackage] { + implicit val sortByModifyDate: Ordering[StoryPackage] = new Ordering[StoryPackage] { def compare(a: StoryPackage, b: StoryPackage) = (a.name, b.name) match { case (None, None) => 0 case (Some(_), None) => -1 diff --git a/app/story_packages/model/frontsapi.scala b/app/story_packages/model/frontsapi.scala index 34aaf40..0cd7f0f 100644 --- a/app/story_packages/model/frontsapi.scala +++ b/app/story_packages/model/frontsapi.scala @@ -19,7 +19,7 @@ trait UpdateActionsTrait extends Logging { def frontsApi: FrontsApi def config: ApplicationConfiguration - implicit val updateListWrite = Json.writes[UpdateList] + implicit val updateListWrite: OWrites[UpdateList] = Json.writes[UpdateList] def insertIntoLive(update: UpdateList, identity: User, collectionJson: CollectionJson): CollectionJson = { val live = updateList(update, identity, collectionJson.live) diff --git a/app/story_packages/services/S3.scala b/app/story_packages/services/S3.scala index bb9a633..2c9dfea 100644 --- a/app/story_packages/services/S3.scala +++ b/app/story_packages/services/S3.scala @@ -62,11 +62,11 @@ trait S3 extends Logging { result => new DateTime(result.getObjectMetadata.getLastModified) } - def putPrivate(key: String, value: String, contentType: String) { + def putPrivate(key: String, value: String, contentType: String): Unit = { put(key: String, value: String, contentType: String, Private) } - private def put(key: String, value: String, contentType: String, accessControlList: CannedAccessControlList) { + private def put(key: String, value: String, contentType: String, accessControlList: CannedAccessControlList): Unit = { val metadata = new ObjectMetadata() metadata.setCacheControl("no-cache,no-store") metadata.setContentType(contentType) diff --git a/app/story_packages/switchboard/Switchboard.scala b/app/story_packages/switchboard/Switchboard.scala index 588f2f9..7e8e976 100644 --- a/app/story_packages/switchboard/Switchboard.scala +++ b/app/story_packages/switchboard/Switchboard.scala @@ -20,7 +20,7 @@ class Lifecycle(conf: SwitchboardConfiguration, scheduler: Scheduler) extends Lo Logger.info("Starting switchboard cache") scheduler.scheduleWithFixedDelay(initialDelay = 1.seconds, delay = 1.minute) { () => refreshSwitches() } - def refreshSwitches() { + def refreshSwitches(): Unit = { Logger.info("Refreshing switches from switchboard") client.getSwitches() foreach { response => SwitchManager.updateSwitches(response) } } diff --git a/app/story_packages/updates/KinesisEventSender.scala b/app/story_packages/updates/KinesisEventSender.scala index 00664e2..5d77197 100644 --- a/app/story_packages/updates/KinesisEventSender.scala +++ b/app/story_packages/updates/KinesisEventSender.scala @@ -121,7 +121,7 @@ class KinesisEventSender(config: ApplicationConfiguration) extends Logging { articles = createUpdatePayload(collectionJson))) } - def sendUpdate(streamName: String, collectionId: String, event: Event) { + def sendUpdate(streamName: String, collectionId: String, event: Event): Unit = { val request = new PutRecordsRequest().withStreamName(streamName) val bytes = ThriftSerializer.serializeToBytes(event, Some(GzipType), Some(128)) if (bytes.length > config.updates.maxDataSize) { diff --git a/app/story_packages/updates/Reindex.scala b/app/story_packages/updates/Reindex.scala index 4356c6b..29d9916 100644 --- a/app/story_packages/updates/Reindex.scala +++ b/app/story_packages/updates/Reindex.scala @@ -11,6 +11,7 @@ import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future import scala.concurrent.duration._ import scala.util.control.NonFatal +import play.api.libs.json.OFormat case class ReindexPage( totalCount: Int, @@ -39,7 +40,7 @@ case class ReindexProgress( documentsExpected: Int ) object ReindexProgress { - implicit val jsonFormat = Json.format[ReindexProgress] + implicit val jsonFormat: OFormat[ReindexProgress] = Json.format[ReindexProgress] } sealed trait ReindexStatus{val label: String} diff --git a/app/story_packages/updates/UpdateMessage.scala b/app/story_packages/updates/UpdateMessage.scala index af267bd..6f10c14 100644 --- a/app/story_packages/updates/UpdateMessage.scala +++ b/app/story_packages/updates/UpdateMessage.scala @@ -31,7 +31,7 @@ case class Remove(remove: UpdateList) extends UpdateMessage /* Macro - Watch out, this needs to be after the case classes */ object UpdateMessage { - implicit val format = derived.flat.oformat[UpdateMessage]((__ \ "type").format[String]) + implicit val format: OFormat[UpdateMessage] = derived.flat.oformat[UpdateMessage]((__ \ "type").format[String]) } /* Kinesis messages */ diff --git a/project/plugins.sbt b/project/plugins.sbt index 3b5e6c9..b9c585b 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -11,3 +11,5 @@ addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19") addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0") libraryDependencies += "org.vafer" % "jdeb" % "1.3" artifacts (Artifact("jdeb", "jar", "jar")) + +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")