Skip to content

Commit

Permalink
internal: Introduce scalafix (#3328)
Browse files Browse the repository at this point in the history
Testing scalafix.

Due to scala2/3 compatibilities, we cannot enable some common rules, but
at least scalacenter/scalafix#542 worked
  • Loading branch information
xerial authored Jan 9, 2024
1 parent 2848d4a commit 9fbb607
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 8 deletions.
12 changes: 12 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
rules = [
# ExplicitResultTypes,
# OrganizeImports,
# RemoveUnused,
DisableSyntax,
LeakingImplicitClassVal,
NoValInForComprehension,
# ProcedureSyntax, // Scala-2 only
// Need to preserve string-interpolation prefix for `s"..."` and `f"..."` for
// preservinng the code alignment
# RedundantSyntax
]
2 changes: 1 addition & 1 deletion airframe-di/src/main/scala/wvlet/airframe/Session.scala
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ object Session extends LogSupport {
*
* @param session
*/
implicit class SessionAccess(val session: Session) extends AnyVal {
implicit class SessionAccess(private val session: Session) extends AnyVal {
def get[A](surface: Surface)(implicit sourceCode: SourceCode): A = session.get[A](surface)(sourceCode)
def getOrElse[A](surface: Surface, obj: => A)(implicit sourceCode: SourceCode): A =
session.getOrElse[A](surface, obj)(sourceCode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object HttpClientGenerator extends LogSupport {
}
}

private[client] implicit class RichSurface(val s: Surface) extends AnyVal {
private[client] implicit class RichSurface(private val s: Surface) extends AnyVal {
def fullTypeName: String = fullTypeNameOf(s)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ object GrpcContext {
private[grpc] val KEY_ACCEPT = Metadata.Key.of("accept", Metadata.ASCII_STRING_MARSHALLER)
private[grpc] val KEY_CONTENT_TYPE = Metadata.Key.of("content-type", Metadata.ASCII_STRING_MARSHALLER)

private[grpc] implicit class RichMetadata(val m: Metadata) extends AnyVal {
private[grpc] implicit class RichMetadata(private val m: Metadata) extends AnyVal {
def accept: String = Option(m.get(KEY_ACCEPT)).getOrElse(RPCEncoding.ApplicationMsgPack)
def setAccept(s: String): Unit = {
m.removeAll(KEY_ACCEPT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import java.util.concurrent.ExecutorService
/**
*/
object GrpcServiceBuilder {
private implicit class RichMethod(val m: MethodSurface) extends AnyVal {
private implicit class RichMethod(private val m: MethodSurface) extends AnyVal {

private def findClientStreamingArg: Option[MethodParameter] = {
m.args.find(x => classOf[Rx[_]].isAssignableFrom(x.surface.rawType))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ package object json {
// Alias to encode msgpack into JSON strings with airframe-codec
type Json = String

implicit class RichJson(val json: Json) extends AnyVal {
implicit class RichJson(private val json: Json) extends AnyVal {
def toJSONValue: JSONValue = JSON.parseAny(json)
}

implicit class JSONValueOps(val jsonValue: JSONValue) extends AnyVal {
implicit class JSONValueOps(private val jsonValue: JSONValue) extends AnyVal {
def /(name: String): Seq[JSONValue] = {
jsonValue match {
case jsonObject: JSONObject =>
Expand Down Expand Up @@ -95,7 +95,7 @@ package object json {
}
}

implicit class JSONValueSeqOps(val jsonValues: Seq[JSONValue]) extends AnyVal {
implicit class JSONValueSeqOps(private val jsonValues: Seq[JSONValue]) extends AnyVal {
def /(name: String): Seq[JSONValue] = {
jsonValues.flatMap { jsonValue => jsonValue / name }
}
Expand Down
2 changes: 1 addition & 1 deletion airframe-rx/src/main/scala/wvlet/airframe/rx/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import scala.concurrent.{ExecutionContext, Future}
/**
*/
package object rx {
implicit class FutureConverter[A](val f: Future[A]) extends AnyVal {
implicit class FutureConverter[A](private val f: Future[A]) extends AnyVal {
def toRx(implicit ec: ExecutionContext): RxOption[A] = Rx.fromFuture(f)(ec)
}
}
3 changes: 3 additions & 0 deletions project/plugin.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.3.2")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("org.jetbrains.scala" % "sbt-ide-settings" % "1.1.2")

// For auto-code rewrite
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.1")

// For integration testing
val SBT_AIRFRAME_VERSION = sys.env.getOrElse("SBT_AIRFRAME_VERSION", "23.12.1")
addSbtPlugin("org.wvlet.airframe" % "sbt-airframe" % SBT_AIRFRAME_VERSION)
Expand Down

0 comments on commit 9fbb607

Please sign in to comment.