Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Scalafmt to the latest version to enable Scala 3 formatting #230

Merged
merged 10 commits into from
Jan 24, 2022
Merged
Prev Previous commit
Next Next commit
Update format
  • Loading branch information
ekrich committed Jan 24, 2022
commit 0d3f1388cb503bd21f57897801937583361f62d3
18 changes: 9 additions & 9 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def versionFmt(out: sbtdynver.GitDescribeOutput): String = {

val dotcOpts = List("-unchecked", "-deprecation", "-feature")
val scalacOpts = dotcOpts ++ List(
//"-Ywarn-unused:imports", // no 2.11 - maybe time for sbt-tpolecat
// "-Ywarn-unused:imports", // no 2.11 - maybe time for sbt-tpolecat
"-Xsource:3"
//"-Xlint:nonlocal-return" // no 2.11/2.12
// "-Xlint:nonlocal-return" // no 2.11/2.12
)

Compile / console / scalacOptions --= Seq(
Expand All @@ -46,9 +46,9 @@ val scala300 = "3.1.0"
val javaTime = "1.1.8"
val scCompat = "2.6.0"

val versionsBase = Seq(scala211, scala212, scala213)
val versionsJVM = versionsBase :+ scala300
val versionsJS = versionsJVM
val versionsBase = Seq(scala211, scala212, scala213)
val versionsJVM = versionsBase :+ scala300
val versionsJS = versionsJVM
val versionsNative = versionsJVM

ThisBuild / scalaVersion := scala212
Expand Down Expand Up @@ -156,12 +156,12 @@ lazy val sconfig = crossProject(JVMPlatform, NativePlatform, JSPlatform)
Test / run / fork := true,
// env vars for tests
Test / envVars ++= Map(
"testList.0" -> "0",
"testList.1" -> "1",
"testList.0" -> "0",
"testList.1" -> "1",
"testClassesPath" -> (Test / classDirectory).value.getPath
),
// uncomment for debugging
//Test / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
// Test / javaOptions += "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",
// mima settings
mimaPreviousArtifacts := Set("org.ekrich" %% "sconfig" % prevVersion),
mimaBinaryIssueFilters ++= ignoredABIProblems
Expand Down Expand Up @@ -236,7 +236,7 @@ lazy val sharedJvmNativeSource: Seq[Setting[_]] = Def.settings(
lazy val sconfigJVM = sconfig.jvm
.dependsOn(testLibJVM % "test->test")
lazy val sconfigNative = sconfig.native
lazy val sconfigJS = sconfig.js
lazy val sconfigJS = sconfig.js

lazy val ignoredABIProblems = {
import com.typesafe.tools.mima.core._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class SimpleLibSettings(config: Config) {

// note that these fields are NOT lazy, because if we're going to
// get any exceptions, we want to get them on startup.
val foo = config.getString("simple-lib.foo")
val hello = config.getString("simple-lib.hello")
val foo = config.getString("simple-lib.foo")
val hello = config.getString("simple-lib.hello")
val whatever = config.getString("simple-lib.whatever")
}

Expand Down
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ val scalaJSVersion = "1.8.0"
val scalaNativeVersion = "0.4.3"

// includes sbt-dynver sbt-pgp sbt-sonatype sbt-git
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.10")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")

// Scala Native support
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % crossVer)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)
addSbtPlugin("org.scala-native" % "sbt-scala-native" % scalaNativeVersion)

// Scala.js support
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % crossVer)
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ private object ConfigParseOptionsEmptyParenFunCall
"getClassLoader",
"getIncluder",
"getOriginDescription",
"getSyntax")
"getSyntax"
)

private object ConfigRenderOptionsEmptyParenFunCall
extends AbstractEmptyParenFunCall(
Expand All @@ -107,7 +108,8 @@ private object ConfigRenderOptionsEmptyParenFunCall
"getComments",
"getFormatted",
"getJson",
"getOriginComments")
"getOriginComments"
)

private object ConfigResolveOptionsEmptyParenFunCall
extends AbstractEmptyParenFunCall(
Expand All @@ -116,31 +118,38 @@ private object ConfigResolveOptionsEmptyParenFunCall
"getAllowUnresolved",
"getResolver",
"getUseSystemEnvironment",
"noSystem")
"noSystem"
)

private object ConfigDocumentEmptyParenFunCall
extends AbstractEmptyParenFunCall(
Symbol("com/typesafe/config/parser/ConfigDocument#"),
"render")
"render"
)

private object ConfigNodeEmptyParenFunCall
extends AbstractEmptyParenFunCall(
Symbol("com/typesafe/config/parser/ConfigNode#"),
"render")
"render"
)

private abstract class AbstractEmptyParenFunCall(
typesafeConfigSymbol: Symbol,
atLeastOneMethodName: String,
emptyParenMethodNames: String*) {
emptyParenMethodNames: String*
) {
def unapply(tree: Tree)(implicit doc: SemanticDocument): Option[Term] =
EmptyParenFunCallsOnSymbol(typesafeConfigSymbol,
atLeastOneMethodName +: emptyParenMethodNames,
tree)
EmptyParenFunCallsOnSymbol(
typesafeConfigSymbol,
atLeastOneMethodName +: emptyParenMethodNames,
tree
)
}

private object EmptyParenFunCallsOnSymbol {
def apply(symbol: Symbol, methodNames: Seq[String], tree: Tree)(
implicit doc: SemanticDocument): Option[Term] = {
def apply(symbol: Symbol, methodNames: Seq[String], tree: Tree)(implicit
doc: SemanticDocument
): Option[Term] = {

object SelectSymbolEmptyParenMethod {
def unapply(subtree: Tree)(implicit doc: SemanticDocument): Option[Term] =
Expand All @@ -156,12 +165,15 @@ private object EmptyParenFunCallsOnSymbol {
}

object SymbolEmptyParenMethod {
def unapply(term: Term.Name)(
implicit doc: SemanticDocument): Option[MethodSignature] =
def unapply(
term: Term.Name
)(implicit doc: SemanticDocument): Option[MethodSignature] =
PartialFunction.condOpt(term) {
case Term.Name(name) & XSymbol(
XSymbol.Owner(DoesSymbolHaveCorrectType()) & XSignature(
sig: MethodSignature)) if methodNames contains name =>
sig: MethodSignature
)
) if methodNames contains name =>
sig
}
}
Expand Down
38 changes: 23 additions & 15 deletions scalafix/rules/src/main/scala/org/ekrich/sconfig/fix/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ import scala.util.control.NonFatal
*/
package object fix {

/** Allows to apply multiple extractors/matchers to a single expression in a `case` block.
/**
* Allows to apply multiple extractors/matchers to a single expression in a
* `case` block.
*/
object & {
def unapply[A](a: A): Option[(A, A)] = Some((a, a))
Expand Down Expand Up @@ -88,26 +90,31 @@ package object fix {
*/
None
case NonFatal(ex) =>
throw UnexpectedException(sym,
Properties.javaVersion,
Properties.versionString,
ex)
throw UnexpectedException(
sym,
Properties.javaVersion,
Properties.versionString,
ex
)
}
}

object XSemanticType {

/** Tries to infer a result SemanticType of a particular Stat.
/**
* Tries to infer a result SemanticType of a particular Stat.
*
* @note Not all possible cases are handled.
* @note
* Not all possible cases are handled.
*/
def unapply(stat: Stat)(
implicit doc: SemanticDocument): Option[SemanticType] =
def unapply(
stat: Stat
)(implicit doc: SemanticDocument): Option[SemanticType] =
PartialFunction.condOpt(stat) {
case Term.Name(_) & XSymbol(XSignature(ValueSignature(tpe))) => tpe

case Term.Apply(_, _) &
XSymbol(XSignature(ValueSignature(TypeRef(_, funcSym, _ :+ tpe))))
XSymbol(XSignature(ValueSignature(TypeRef(_, funcSym, _ :+ tpe))))
if funcSym.value.startsWith("scala/Function") && funcSym.value
.endsWith("#") =>
tpe
Expand All @@ -117,11 +124,12 @@ package object fix {
}
}

case class UnexpectedException(sym: Symbol,
java: String,
scala: String,
cause: Throwable)
extends RuntimeException(
case class UnexpectedException(
sym: Symbol,
java: String,
scala: String,
cause: Throwable
) extends RuntimeException(
s"""An unexpected exception occurred. Please report this as an issue at https://github.com/ekrich/sconfig/issues and include the following information:
|
|Failing symbol: ${sym.value}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package org.ekrich.config
import org.ekrich.config.impl.ConfigBeanImpl

/**
* Factory for automatically creating a Java class from a {@link Config}.
* See {@link ConfigBeanFactory#create}.
* Factory for automatically creating a Java class from a {@link Config}. See
* {@link ConfigBeanFactory#create}.
*
* @since 1.3.0
*/
object ConfigBeanFactory {

/**
* Creates an instance of a class, initializing its fields from a {@link Config}.
* Creates an instance of a class, initializing its fields from a {@link
* Config}.
*
* Example usage:
*
Expand All @@ -20,27 +21,29 @@ object ConfigBeanFactory {
* val config: FooConfig = ConfigBeanFactory.create(configSource, classOf[FooConfig]);
* }}}
*
* The Java class should follow JavaBean conventions. Field types
* can be any of the types you can normally get from a {@link Config},
* including `java.time.Duration` or {@link ConfigMemorySize}.
* Fields may also be another JavaBean-style
* class.
* The Java class should follow JavaBean conventions. Field types can be any
* of the types you can normally get from a {@link Config}, including
* `java.time.Duration` or {@link ConfigMemorySize}. Fields may also be
* another JavaBean-style class.
*
* Fields are mapped to config by converting the config key to
* camel case. So the key `foo-bar` becomes JavaBean
* setter `setFooBar`.
* Fields are mapped to config by converting the config key to camel case. So
* the key `foo-bar` becomes JavaBean setter `setFooBar`.
*
* @since 1.3.0
* @param config source of config information
* @param clazz class to be instantiated
* @param [T] the type of the class to be instantiated
* @return an instance of the class populated with data from the config
* @param config
* source of config information
* @param clazz
* class to be instantiated
* @param [T]
* the type of the class to be instantiated
* @return
* an instance of the class populated with data from the config
* @throws ConfigException#BadBean
* If something is wrong with the JavaBean
* If something is wrong with the JavaBean
* @throws ConfigException#ValidationFailed
* If the config doesn't conform to the bean's implied schema
* If the config doesn't conform to the bean's implied schema
* @throws ConfigException
* Can throw the same exceptions as the getters on {@link Config}
* Can throw the same exceptions as the getters on {@link Config}
*/
def create[T](config: Config, clazz: Class[T]): T =
ConfigBeanImpl.createInternal(config, clazz)
Expand Down
Loading