From 690dd4571e59612f9b16f89b22cc390de47a6843 Mon Sep 17 00:00:00 2001 From: Meriam Lachkar Date: Wed, 16 Mar 2022 10:27:37 +0100 Subject: [PATCH] Add removeUnused rule --- .scalafix.conf | 3 ++- build.sbt | 3 ++- .../scala/scaladex/core/model/Artifact.scala | 11 ----------- .../core/model/search/ProjectDocument.scala | 2 +- .../scaladex/data/DateTimeSerializer.scala | 2 +- .../scaladex/data/central/CentralMissing.scala | 6 +++--- .../scala/scaladex/infra/CoursierResolver.scala | 2 +- .../scaladex/infra/ElasticsearchEngine.scala | 2 +- .../scaladex/infra/FilesystemStorage.scala | 9 --------- .../scala/scaladex/infra/GithubClient.scala | 7 +++---- .../scala/scaladex/server/GithubAuthImpl.scala | 3 +-- .../src/main/scala/scaladex/server/Server.scala | 7 ++----- .../scala/scaladex/server/TwirlSupport.scala | 2 +- .../scaladex/server/config/ServerConfig.scala | 2 +- .../scala/scaladex/server/route/AdminPage.scala | 7 +------ .../scaladex/server/route/ProjectPages.scala | 17 ++++++++--------- .../scaladex/server/route/api/PublishApi.scala | 17 ++--------------- .../scaladex/server/service/Scheduler.scala | 2 +- .../server/service/SearchSynchronizer.scala | 2 +- .../server/route/ProjectPagesTests.scala | 2 +- .../scala/scaladex/view/SchedulerStatus.scala | 2 +- .../main/scala/scaladex/view/html/package.scala | 4 ++-- 22 files changed, 36 insertions(+), 78 deletions(-) diff --git a/.scalafix.conf b/.scalafix.conf index 8b766ac7a..41109ee2e 100644 --- a/.scalafix.conf +++ b/.scalafix.conf @@ -1,6 +1,7 @@ rules = [ ExplicitResultTypes, - OrganizeImports + OrganizeImports, + RemoveUnused ] ExplicitResultTypes { diff --git a/build.sbt b/build.sbt index 89b1ec96b..91edbca4b 100755 --- a/build.sbt +++ b/build.sbt @@ -52,7 +52,7 @@ lazy val scalacOptionsSettings = Def.settings( "-feature", "-unchecked", "-Xfatal-warnings", - "-Wunused:imports" + "-Wunused" ) ) @@ -150,6 +150,7 @@ lazy val webclient = project .in(file("modules/webclient")) .settings( scalacOptionsSettings, + scalacOptions -= "-Xfatal-warnings", // relax fatal-warnings on webclient libraryDependencies ++= Seq( "com.lihaoyi" %%% "scalatags" % "0.8.6", "be.doeraene" %%% "scalajs-jquery" % "1.0.0", diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala index 65c263f07..e8dd2627b 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/Artifact.scala @@ -150,17 +150,6 @@ case class Artifact( def scastieURL: String = { val tryBaseUrl = "https://scastie.scala-lang.org/try" - def latestFor(version: String): String = { - val latest = - Map( - "2.10" -> "2.10.7", - "2.11" -> "2.11.12", - "2.12" -> "2.12.6" - ) - - latest.getOrElse(version, version) - } - val targetParam = binaryVersion.platform match { case ScalaJs(_) => Some("t" -> "JS") case _ => None diff --git a/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala b/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala index 97e8b1b27..9c996b2be 100644 --- a/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala +++ b/modules/core/shared/src/main/scala/scaladex/core/model/search/ProjectDocument.scala @@ -59,7 +59,7 @@ object ProjectDocument { formerReferences: Seq[Project.Reference] ): ProjectDocument = { import project._ - val binaryVersions = artifacts.map(_.binaryVersion) + artifacts.map(_.binaryVersion) ProjectDocument( organization, repository, diff --git a/modules/data/src/main/scala/scaladex/data/DateTimeSerializer.scala b/modules/data/src/main/scala/scaladex/data/DateTimeSerializer.scala index 2dff23090..2a1451109 100644 --- a/modules/data/src/main/scala/scaladex/data/DateTimeSerializer.scala +++ b/modules/data/src/main/scala/scaladex/data/DateTimeSerializer.scala @@ -8,7 +8,7 @@ import org.json4s._ * Scope serializer, since Scope is not a case class json4s can't handle this by default */ object DateTimeSerializer - extends CustomSerializer[DateTime](format => + extends CustomSerializer[DateTime](_ => ( { case JString(dateTime) => diff --git a/modules/data/src/main/scala/scaladex/data/central/CentralMissing.scala b/modules/data/src/main/scala/scaladex/data/central/CentralMissing.scala index 31d6ff7bc..eda029a6d 100644 --- a/modules/data/src/main/scala/scaladex/data/central/CentralMissing.scala +++ b/modules/data/src/main/scala/scaladex/data/central/CentralMissing.scala @@ -59,7 +59,7 @@ object CentralMissing { } object TimestampSerializer - extends CustomSerializer[DateTime](format => + extends CustomSerializer[DateTime](_ => ( { case JInt(timestamp) => @@ -161,8 +161,8 @@ class CentralMissing(paths: DataPaths)(implicit val system: ActorSystem) { // data/run central /home/gui/scaladex/scaladex-contrib /home/gui/scaladex/scaladex-index /home/gui/scaladex/scaladex-credentials def run(): Unit = { - val metaExtractor = new ArtifactMetaExtractor(paths) - val pomsReader = new PomsReader(new CoursierResolver) + new ArtifactMetaExtractor(paths) + new PomsReader(new CoursierResolver) val allGroups: Set[String] = ??? val artifactsDownloads = allGroups.toList.map(SearchRequest(_)) diff --git a/modules/infra/src/main/scala/scaladex/infra/CoursierResolver.scala b/modules/infra/src/main/scala/scaladex/infra/CoursierResolver.scala index bef5a804d..686d9b768 100644 --- a/modules/infra/src/main/scala/scaladex/infra/CoursierResolver.scala +++ b/modules/infra/src/main/scala/scaladex/infra/CoursierResolver.scala @@ -19,7 +19,7 @@ import coursier.error.ResolutionError import scaladex.core.service.PomResolver class CoursierResolver()(implicit val ec: ExecutionContext) extends PomResolver with LazyLogging { - private val cache = Cache.default + Cache.default private val repositories = Seq( Repositories.central, Repositories.jcenter, diff --git a/modules/infra/src/main/scala/scaladex/infra/ElasticsearchEngine.scala b/modules/infra/src/main/scala/scaladex/infra/ElasticsearchEngine.scala index 290e0e2eb..0d8b6396b 100644 --- a/modules/infra/src/main/scala/scaladex/infra/ElasticsearchEngine.scala +++ b/modules/infra/src/main/scala/scaladex/infra/ElasticsearchEngine.scala @@ -228,7 +228,7 @@ class ElasticsearchEngine(esClient: ElasticClient, index: String)(implicit ec: E .flatMap { hit => parser.decode[GithubIssue](hit.sourceAsString) match { case Right(issue) => Some(issue) - case Left(error) => + case Left(_) => logger.warn("cannot parse beginner issue: ") None } diff --git a/modules/infra/src/main/scala/scaladex/infra/FilesystemStorage.scala b/modules/infra/src/main/scala/scaladex/infra/FilesystemStorage.scala index 8503ffced..8ae626585 100644 --- a/modules/infra/src/main/scala/scaladex/infra/FilesystemStorage.scala +++ b/modules/infra/src/main/scala/scaladex/infra/FilesystemStorage.scala @@ -109,15 +109,6 @@ object FilesystemStorage { directory } - private def initJsonFile(directory: Path, name: String): Path = { - val file = directory.resolve(name) - if (!Files.exists(file)) { - Files.createFile(file) - Files.write(file, "{}".getBytes(StandardCharsets.UTF_8)) - } - file - } - private def initFile(directory: Path, name: String): Path = { val file = directory.resolve(name) if (!Files.exists(file)) { diff --git a/modules/infra/src/main/scala/scaladex/infra/GithubClient.scala b/modules/infra/src/main/scala/scaladex/infra/GithubClient.scala index 0988d8c0a..845a6d063 100644 --- a/modules/infra/src/main/scala/scaladex/infra/GithubClient.scala +++ b/modules/infra/src/main/scala/scaladex/infra/GithubClient.scala @@ -22,7 +22,6 @@ import akka.http.scaladsl.model.headers.OAuth2BearerToken import akka.http.scaladsl.model.headers.RawHeader import akka.http.scaladsl.settings.ConnectionPoolSettings import akka.http.scaladsl.unmarshalling.Unmarshal -import akka.http.scaladsl.unmarshalling.Unmarshaller import akka.stream.scaladsl.Flow import akka.util.ByteString import com.typesafe.scalalogging.LazyLogging @@ -372,9 +371,9 @@ class GithubClient(token: Secret)(implicit val system: ActorSystem) private def process(request: HttpRequest): Future[GithubResponse[(Seq[HttpHeader], ResponseEntity)]] = { assert(request.headers.contains(Authorization(credentials))) queueRequest(request).flatMap { - case r @ HttpResponse(StatusCodes.OK, headers, entity, _) => + case HttpResponse(StatusCodes.OK, headers, entity, _) => Future.successful(GithubResponse.Ok((headers, entity))) - case r @ HttpResponse(StatusCodes.MovedPermanently, headers, entity, _) => + case HttpResponse(StatusCodes.MovedPermanently, headers, entity, _) => entity.discardBytes() val newRequest = HttpRequest(uri = headers.find(_.is("location")).get.value()).withHeaders(request.headers) process(newRequest).map { @@ -382,7 +381,7 @@ class GithubClient(token: Secret)(implicit val system: ActorSystem) case other => other } case _ @HttpResponse(code, _, entity, _) => - implicit val unmarshaller = Unmarshaller.byteStringUnmarshaller +// implicit val unmarshaller = Unmarshaller.byteStringUnmarshaller Unmarshal(entity).to[String].map(errorMessage => GithubResponse.Failed(code.intValue, errorMessage)) } } diff --git a/modules/server/src/main/scala/scaladex/server/GithubAuthImpl.scala b/modules/server/src/main/scala/scaladex/server/GithubAuthImpl.scala index a8d0fc89e..a92effcfa 100644 --- a/modules/server/src/main/scala/scaladex/server/GithubAuthImpl.scala +++ b/modules/server/src/main/scala/scaladex/server/GithubAuthImpl.scala @@ -9,7 +9,6 @@ import akka.http.scaladsl.model.Uri._ import akka.http.scaladsl.model._ import akka.http.scaladsl.model.headers._ import akka.http.scaladsl.unmarshalling.Unmarshal -import scaladex.core.model.Env import scaladex.core.model.UserState import scaladex.core.service.GithubAuth import scaladex.core.util.ScalaExtensions._ @@ -22,7 +21,7 @@ object Response { } } //todo: remove Json4sSupport -class GithubAuthImpl(env: Env)(implicit sys: ActorSystem) extends GithubAuth with Json4sSupport { +class GithubAuthImpl()(implicit sys: ActorSystem) extends GithubAuth with Json4sSupport { import sys.dispatcher def getUserStateWithToken(token: String): Future[UserState] = getUserState(Secret(token)) diff --git a/modules/server/src/main/scala/scaladex/server/Server.scala b/modules/server/src/main/scala/scaladex/server/Server.scala index 5c0267ce5..8ead690c0 100644 --- a/modules/server/src/main/scala/scaladex/server/Server.scala +++ b/modules/server/src/main/scala/scaladex/server/Server.scala @@ -16,7 +16,6 @@ import com.softwaremill.session.SessionDirectives._ import com.softwaremill.session.SessionOptions._ import com.typesafe.scalalogging.LazyLogging import doobie.util.ExecutionContexts -import scaladex.core.service.Storage import scaladex.core.service.WebDatabase import scaladex.data.util.PidLock import scaladex.infra.DataPaths @@ -89,7 +88,6 @@ object Server extends LazyLogging { webDatabase, schedulerService, adminTaskService, - filesystem, publishProcess ) _ <- IO( @@ -141,20 +139,19 @@ object Server extends LazyLogging { webDatabase: WebDatabase, schedulerService: SchedulerService, adminTaskService: AdminTaskService, - filesystem: Storage, publishProcess: PublishProcess )( implicit actor: ActorSystem ): Route = { import actor.dispatcher - val githubAuth = new GithubAuthImpl(config.env) + val githubAuth = new GithubAuthImpl() val session = new GithubUserSession(config.session) val searchPages = new SearchPages(config.env, searchEngine) val frontPage = new FrontPage(config.env, webDatabase, searchEngine) val adminPages = new AdminPage(config.env, schedulerService, adminTaskService) - val projectPages = new ProjectPages(config.env, webDatabase, searchEngine, filesystem) + val projectPages = new ProjectPages(config.env, webDatabase, searchEngine) val awesomePages = new AwesomePages(config.env, searchEngine) val programmaticRoutes = concat( diff --git a/modules/server/src/main/scala/scaladex/server/TwirlSupport.scala b/modules/server/src/main/scala/scaladex/server/TwirlSupport.scala index 5d6cce955..ca28e9c7a 100644 --- a/modules/server/src/main/scala/scaladex/server/TwirlSupport.scala +++ b/modules/server/src/main/scala/scaladex/server/TwirlSupport.scala @@ -27,7 +27,7 @@ trait TwirlSupport { twirlMarshaller[Xml](`text/xml`) /** Serialize Twirl formats to `String`. */ - protected def twirlMarshaller[A <: AnyRef: Manifest]( + protected def twirlMarshaller[A <: AnyRef]( contentType: MediaType ): ToEntityMarshaller[A] = Marshaller.StringMarshaller.wrap(contentType)(_.toString) diff --git a/modules/server/src/main/scala/scaladex/server/config/ServerConfig.scala b/modules/server/src/main/scala/scaladex/server/config/ServerConfig.scala index 184be0841..c7e43744b 100644 --- a/modules/server/src/main/scala/scaladex/server/config/ServerConfig.scala +++ b/modules/server/src/main/scala/scaladex/server/config/ServerConfig.scala @@ -33,7 +33,7 @@ object ServerConfig { val oauth2 = OAuth2Config.from(config) val database = DatabaseConfig.from(config).get val elasticsearch = ElasticsearchConfig.from(config) - val tempDir = config.getString("scaladex.filesystem.temp") + config.getString("scaladex.filesystem.temp") val filesystem = FilesystemConfig.from(config) val github = GithubConfig.from(config) diff --git a/modules/server/src/main/scala/scaladex/server/route/AdminPage.scala b/modules/server/src/main/scala/scaladex/server/route/AdminPage.scala index 9207f9f1a..d2df04bb8 100644 --- a/modules/server/src/main/scala/scaladex/server/route/AdminPage.scala +++ b/modules/server/src/main/scala/scaladex/server/route/AdminPage.scala @@ -1,7 +1,4 @@ package scaladex.server.route - -import scala.concurrent.ExecutionContext - import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.model.Uri import akka.http.scaladsl.server.Directives._ @@ -14,9 +11,7 @@ import scaladex.server.service.AdminTaskService import scaladex.server.service.SchedulerService import scaladex.view -class AdminPage(env: Env, schedulerSrv: SchedulerService, adminTaskService: AdminTaskService)( - implicit ec: ExecutionContext -) { +class AdminPage(env: Env, schedulerSrv: SchedulerService, adminTaskService: AdminTaskService) { def route(user: Option[UserState]): Route = pathPrefix("admin") { diff --git a/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala b/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala index 6c867794f..f6b9228cc 100644 --- a/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala +++ b/modules/server/src/main/scala/scaladex/server/route/ProjectPages.scala @@ -24,13 +24,12 @@ import scaladex.core.model.Project import scaladex.core.model.SemanticVersion import scaladex.core.model.UserState import scaladex.core.service.SearchEngine -import scaladex.core.service.Storage import scaladex.core.service.WebDatabase import scaladex.server.TwirlSupport._ import scaladex.server.service.SearchSynchronizer import scaladex.view -class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine, localStorage: Storage)( +class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine)( implicit executionContext: ExecutionContext ) extends LazyLogging { private val searchSynchronizer = new SearchSynchronizer(database, searchEngine) @@ -89,7 +88,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine, .sortBy(_._1)(SemanticVersion.ordering.reverse) complete(view.html.artifacts(env, project, user, binaryVersionByPlatforms, artifactsByVersions)) - case Failure(e) => + case Failure(_) => complete(StatusCodes.NotFound, view.html.notfound(env, user)) } } @@ -152,7 +151,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine, ) onComplete(res) { case Success((code, some)) => complete(code, some) - case Failure(e) => + case Failure(_) => complete(StatusCodes.NotFound, view.html.notfound(env, user)) } } @@ -164,7 +163,7 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine, val res = getProjectPage(organization, repository, binaryVersion, artifact, Some(version), user) onComplete(res) { case Success((code, some)) => complete(code, some) - case Failure(e) => + case Failure(_) => complete(StatusCodes.NotFound, view.html.notfound(env, user)) } } @@ -277,10 +276,10 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine, rawCustomScalaDoc, rawCategory, rawBeginnerIssuesLabel, - selectedBeginnerIssues, - rawChatroom, - rawContributingGuide, - rawCodeOfConduct + _, + _, + _, + _ ) => val documentationLinks = fields._1 diff --git a/modules/server/src/main/scala/scaladex/server/route/api/PublishApi.scala b/modules/server/src/main/scala/scaladex/server/route/api/PublishApi.scala index 772fb7d55..2669bc006 100644 --- a/modules/server/src/main/scala/scaladex/server/route/api/PublishApi.scala +++ b/modules/server/src/main/scala/scaladex/server/route/api/PublishApi.scala @@ -14,7 +14,6 @@ import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server.Route import akka.http.scaladsl.server.directives._ import com.typesafe.scalalogging.LazyLogging -import scaladex.core.model.Artifact import scaladex.core.model.UserState import scaladex.core.service.GithubAuth import scaladex.server.route._ @@ -36,7 +35,7 @@ class PublishApi( credentialsHeader: Option[HttpCredentials] ): Credentials => Future[Option[(String, UserState)]] = { - case Credentials.Provided(username) => + case Credentials.Provided(_) => credentialsHeader match { case Some(cred) => val upw = new String( @@ -70,18 +69,6 @@ class PublishApi( * @param path the real publishing path * @return MavenReference */ - private def mavenPathExtractor(path: String): Artifact.MavenReference = { - - val segments = path.split("/").toList - val size = segments.size - val takeFrom = if (segments.head.isEmpty) 1 else 0 - - val artifactId = segments(size - 3) - val version = segments(size - 2) - val groupId = segments.slice(takeFrom, size - 3).mkString(".") - - Artifact.MavenReference(groupId, artifactId, version) - } private val githubCredentialsCache = MMap.empty[String, (String, UserState)] @@ -90,7 +77,7 @@ class PublishApi( concat( get( path("publish")( - parameter("path")(path => + parameter("path")(_ => complete { /* check if the artifact already exists - sbt will handle HTTP-Status codes * NotFound -> allowed to write diff --git a/modules/server/src/main/scala/scaladex/server/service/Scheduler.scala b/modules/server/src/main/scala/scaladex/server/service/Scheduler.scala index 313d71f00..a0a36268e 100644 --- a/modules/server/src/main/scala/scaladex/server/service/Scheduler.scala +++ b/modules/server/src/main/scala/scaladex/server/service/Scheduler.scala @@ -27,7 +27,7 @@ abstract class Scheduler(val name: String, frequency: FiniteDuration)(implicit e def start(): Unit = status match { - case s: SchedulerStatus.Started => () + case _: SchedulerStatus.Started => () case _ => val can = scheduler.scheduleWithFixedDelay(0.minute, frequency) { _status = SchedulerStatus.Started(name, Instant.now, frequency, running = false, None, None) diff --git a/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala b/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala index bda52fdbf..2bc160ae8 100644 --- a/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala +++ b/modules/server/src/main/scala/scaladex/server/service/SearchSynchronizer.scala @@ -25,7 +25,7 @@ class SearchSynchronizer(database: WebDatabase, searchEngine: SearchEngine)(impl case (p, GithubStatus.Moved(_, newRef)) => newRef -> p.reference } - .groupMap { case (newRef, ref) => newRef } { case (newRef, ref) => ref } + .groupMap { case (newRef, _) => newRef } { case (_, ref) => ref } projectsToDelete = deprecatedProjects ++ allProjectsAndStatus.collect { case (p, GithubStatus.NotFound(_)) => p.reference } projectsToSync = allProjectsAndStatus diff --git a/modules/server/src/test/scala/scaladex/server/route/ProjectPagesTests.scala b/modules/server/src/test/scala/scaladex/server/route/ProjectPagesTests.scala index e9d7ae561..a824e5aa1 100644 --- a/modules/server/src/test/scala/scaladex/server/route/ProjectPagesTests.scala +++ b/modules/server/src/test/scala/scaladex/server/route/ProjectPagesTests.scala @@ -23,7 +23,7 @@ class ProjectPagesTests extends ControllerBaseSuite with BeforeAndAfterEach { override def beforeEach(): Unit = Await.result(insertPlayJson(), Duration.Inf) - val projectPages = new ProjectPages(config.env, database, searchEngine, localStorage) + val projectPages = new ProjectPages(config.env, database, searchEngine) val route: Route = projectPages.route(None) describe("GET organization/repository") { diff --git a/modules/template/src/main/scala/scaladex/view/SchedulerStatus.scala b/modules/template/src/main/scala/scaladex/view/SchedulerStatus.scala index d64ca2ae5..b6cd28540 100644 --- a/modules/template/src/main/scala/scaladex/view/SchedulerStatus.scala +++ b/modules/template/src/main/scala/scaladex/view/SchedulerStatus.scala @@ -21,7 +21,7 @@ sealed trait SchedulerStatus { case _ => false } def isStarted(): Boolean = this match { - case s: SchedulerStatus.Started => true + case _: SchedulerStatus.Started => true case _ => false } } diff --git a/modules/template/src/main/scala/scaladex/view/html/package.scala b/modules/template/src/main/scala/scaladex/view/html/package.scala index b4e96344d..84f9b38b9 100644 --- a/modules/template/src/main/scala/scaladex/view/html/package.scala +++ b/modules/template/src/main/scala/scaladex/view/html/package.scala @@ -103,8 +103,8 @@ package object html { if (max < toShow) (min, max) else { (left, right) match { - case (l, r) if l < min => (min, min + toShow - 1) - case (l, r) if r > max => (max - toShow + 1, max) + case (l, _) if l < min => (min, min + toShow - 1) + case (_, r) if r > max => (max - toShow + 1, max) case (l, r) => (l, r - 1 + toShow % 2) } }