Skip to content

Commit

Permalink
Add removeUnused rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mlachkar committed Mar 16, 2022
1 parent 35d2e69 commit 690dd45
Show file tree
Hide file tree
Showing 22 changed files with 36 additions and 78 deletions.
3 changes: 2 additions & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
rules = [
ExplicitResultTypes,
OrganizeImports
OrganizeImports,
RemoveUnused
]

ExplicitResultTypes {
Expand Down
3 changes: 2 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ lazy val scalacOptionsSettings = Def.settings(
"-feature",
"-unchecked",
"-Xfatal-warnings",
"-Wunused:imports"
"-Wunused"
)
)

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object ProjectDocument {
formerReferences: Seq[Project.Reference]
): ProjectDocument = {
import project._
val binaryVersions = artifacts.map(_.binaryVersion)
artifacts.map(_.binaryVersion)
ProjectDocument(
organization,
repository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ object CentralMissing {
}

object TimestampSerializer
extends CustomSerializer[DateTime](format =>
extends CustomSerializer[DateTime](_ =>
(
{
case JInt(timestamp) =>
Expand Down Expand Up @@ -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(_))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -372,17 +371,17 @@ 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 {
case GithubResponse.Ok(res) => GithubResponse.MovedPermanently(res)
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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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))
Expand Down
7 changes: 2 additions & 5 deletions modules/server/src/main/scala/scaladex/server/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,7 +88,6 @@ object Server extends LazyLogging {
webDatabase,
schedulerService,
adminTaskService,
filesystem,
publishProcess
)
_ <- IO(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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._
Expand All @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
}
}
Expand Down Expand Up @@ -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))
}
}
Expand All @@ -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))
}
}
Expand Down Expand Up @@ -277,10 +276,10 @@ class ProjectPages(env: Env, database: WebDatabase, searchEngine: SearchEngine,
rawCustomScalaDoc,
rawCategory,
rawBeginnerIssuesLabel,
selectedBeginnerIssues,
rawChatroom,
rawContributingGuide,
rawCodeOfConduct
_,
_,
_,
_
) =>
val documentationLinks =
fields._1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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(
Expand Down Expand Up @@ -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)]
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 690dd45

Please sign in to comment.