diff --git a/.scalafmt.conf b/.scalafmt.conf index e7207db..90fa4e1 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,14 +1,12 @@ -version = 2.4.2 -edition = 2019-10 +version = 3.10.7 +runner.dialect = Scala212Source3 maxColumn = 100 project.git = true # http://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style. # scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala -docstrings = JavaDoc - -# This also seems more idiomatic to include whitespace in import x.{ yyy } -spaces.inImportCurlyBraces = true +docstrings.style = Asterisk +docstrings.wrap = no # This also seems more idiomatic to include whitespace in import x.{ yyy } spaces.inImportCurlyBraces = true @@ -19,6 +17,14 @@ align.openParenCallSite = false align.openParenDefnSite = false # For better code clarity -danglingParentheses = true +danglingParentheses.preset = true trailingCommas = preserve + +rewrite.scala3.convertToNewSyntax = true +runner.dialectOverride { + allowSignificantIndentation = false + allowAsForImportRename = false + allowStarWildcardImport = false + allowPostfixStarVarargSplices = false +} diff --git a/build.sbt b/build.sbt index 2b07512..8556d7f 100644 --- a/build.sbt +++ b/build.sbt @@ -69,7 +69,7 @@ lazy val treeExample = (project in (file("examples") / "bt")) }) .settings(relaxOldScala) -def relaxOldScala: Seq[Setting[_]] = Seq( +def relaxOldScala: Seq[Setting[?]] = Seq( scalacOptions := { val old = scalacOptions.value CrossVersion.partialVersion(scalaVersion.value) match { diff --git a/core/src/main/scala-2.13+/LowPriorityCollectionTypes.scala b/core/src/main/scala-2.13+/LowPriorityCollectionTypes.scala index 3eaa943..aa04515 100644 --- a/core/src/main/scala-2.13+/LowPriorityCollectionTypes.scala +++ b/core/src/main/scala-2.13+/LowPriorityCollectionTypes.scala @@ -3,8 +3,8 @@ package sbinary import scala.collection.Factory trait LowPriorityCollectionTypes extends Generic { - def canBuildFormat[CC[X] <: Iterable[X], T]( - implicit bin: Format[T], + def canBuildFormat[CC[X] <: Iterable[X], T](implicit + bin: Format[T], cbf: Factory[T, CC[T]] ): Format[CC[T]] = new LengthEncoded[CC[T], T] { diff --git a/core/src/main/scala-2.13-/LowPriorityCollectionTypes.scala b/core/src/main/scala-2.13-/LowPriorityCollectionTypes.scala index 88fffd3..ee53fcf 100644 --- a/core/src/main/scala-2.13-/LowPriorityCollectionTypes.scala +++ b/core/src/main/scala-2.13-/LowPriorityCollectionTypes.scala @@ -3,8 +3,8 @@ package sbinary import scala.collection.generic.CanBuildFrom trait LowPriorityCollectionTypes extends Generic { - def canBuildFormat[CC[X] <: Traversable[X], T]( - implicit bin: Format[T], + def canBuildFormat[CC[X] <: Traversable[X], T](implicit + bin: Format[T], cbf: CanBuildFrom[Nothing, T, CC[T]] ): Format[CC[T]] = new LengthEncoded[CC[T], T] { diff --git a/core/src/main/scala/javaprotocol.scala b/core/src/main/scala/javaprotocol.scala index ab1e57d..012fb14 100644 --- a/core/src/main/scala/javaprotocol.scala +++ b/core/src/main/scala/javaprotocol.scala @@ -3,7 +3,7 @@ package sbinary; import Operations._; trait StandardPrimitives extends CoreProtocol { - private def readUnsigned(in: Input) = in.readByte.toInt & 0xFF + private def readUnsigned(in: Input) = in.readByte.toInt & 0xff implicit object BooleanFormat extends Format[Boolean] { def reads(in: Input) = in.readByte != 0 @@ -13,8 +13,8 @@ trait StandardPrimitives extends CoreProtocol { implicit object CharFormat extends Format[Char] { def reads(in: Input) = ((readUnsigned(in) << 8) + readUnsigned(in)).toChar; def writes(out: Output, t: Char) = { - out.writeByte(((t >>> 8) & 0xFF).toByte); - out.writeByte(((t >>> 0) & 0xFF).toByte); + out.writeByte(((t >>> 8) & 0xff).toByte); + out.writeByte(((t >>> 0) & 0xff).toByte); } } @@ -22,7 +22,7 @@ trait StandardPrimitives extends CoreProtocol { def reads(in: Input) = ((readUnsigned(in) << 8) + readUnsigned(in)).toShort def writes(out: Output, t: Short) = { - out.writeByte(((t >>> 8) & 0xFF).toByte); + out.writeByte(((t >>> 8) & 0xff).toByte); out.writeByte(t.toByte); } } @@ -37,10 +37,10 @@ trait StandardPrimitives extends CoreProtocol { } def writes(out: Output, t: Int): Unit = { - out.writeByte(((t >>> 24) & 0xFF).toByte); - out.writeByte(((t >>> 16) & 0xFF).toByte); - out.writeByte(((t >>> 8) & 0xFF).toByte); - out.writeByte(((t >>> 0) & 0xFF).toByte); + out.writeByte(((t >>> 24) & 0xff).toByte); + out.writeByte(((t >>> 16) & 0xff).toByte); + out.writeByte(((t >>> 8) & 0xff).toByte); + out.writeByte(((t >>> 0) & 0xff).toByte); } } @@ -78,7 +78,7 @@ trait StandardPrimitives extends CoreProtocol { } trait JavaUTF extends CoreProtocol { - private[this] def readUnsignedByte(in: Input): Int = in.readByte.toInt & 0xFF + private[this] def readUnsignedByte(in: Input): Int = in.readByte.toInt & 0xff private[this] def readUnsignedShort(in: Input): Int = (readUnsignedByte(in) << 8) + readUnsignedByte(in) @@ -116,7 +116,7 @@ trait JavaUTF extends CoreProtocol { } while (count < utflen) { - c = bbuffer(count).toInt & 0xFF + c = bbuffer(count).toInt & 0xff cbuffer(charCount) = ((c >> 4) match { case 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 => { count += 1; @@ -127,17 +127,17 @@ trait JavaUTF extends CoreProtocol { if (count > utflen) partial; char2 = bbuffer(count - 1) - if ((char2 & 0xC0) != 0x80) malformed(count); - (((c & 0x1F) << 6) | (char2 & 0x3F)); + if ((char2 & 0xc0) != 0x80) malformed(count); + (((c & 0x1f) << 6) | (char2 & 0x3f)); } case 14 => { count += 3; char2 = bbuffer(count - 2); char3 = bbuffer(count - 1); - if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80)) + if (((char2 & 0xc0) != 0x80) || ((char3 & 0xc0) != 0x80)) malformed(count - 1); - ((c & 0x0F).toInt << 12) | ((char2 & 0x3F).toInt << 6) | ((char3 & 0x3F).toInt << 0); + ((c & 0x0f).toInt << 12) | ((char2 & 0x3f).toInt << 6) | ((char3 & 0x3f).toInt << 0); } case _ => malformed(count); }).toChar @@ -155,8 +155,8 @@ trait JavaUTF extends CoreProtocol { while (i < value.length) { utflen += ( - if ((c >= 0x0001) && (c <= 0x007F)) 1 - else if (c > 0x07FF) 3 + if ((c >= 0x0001) && (c <= 0x007f)) 1 + else if (c > 0x07ff) 3 else 2 ) i += 1; @@ -172,26 +172,26 @@ trait JavaUTF extends CoreProtocol { count += 1; } - append((utflen >>> 8) & 0xFF) - append(utflen & 0xFF) + append((utflen >>> 8) & 0xff) + append(utflen & 0xff) i = 0; - while ((i < value.length) && ((c >= 0x0001) && (c <= 0x007F))) { + while ((i < value.length) && ((c >= 0x0001) && (c <= 0x007f))) { bbuffer(count) = c.toByte; count += 1; i += 1; } while (i < value.length) { - if ((c >= 0x0001) && (c <= 0x007F)) { + if ((c >= 0x0001) && (c <= 0x007f)) { append(c); - } else if (c > 0x07FF) { - append(0xE0 | ((c >> 12) & 0x0F)); - append(0x80 | ((c >> 6) & 0x3F)); - append(0x80 | ((c >> 0) & 0x3F)); + } else if (c > 0x07ff) { + append(0xe0 | ((c >> 12) & 0x0f)); + append(0x80 | ((c >> 6) & 0x3f)); + append(0x80 | ((c >> 0) & 0x3f)); } else { - append(0xC0 | ((c >> 6) & 0x1F)); - append(0x80 | ((c >> 0) & 0x3F)); + append(0xc0 | ((c >> 6) & 0x1f)); + append(0x80 | ((c >> 0) & 0x3f)); } i += 1; diff --git a/core/src/test/scala/binaryTests.scala b/core/src/test/scala/binaryTests.scala index 2f4e69d..2b7aab3 100644 --- a/core/src/test/scala/binaryTests.scala +++ b/core/src/test/scala/binaryTests.scala @@ -45,8 +45,7 @@ object Equal { } } - implicit def eqTuple3[S, T, U]( - implicit + implicit def eqTuple3[S, T, U](implicit eqS: Equal[S], eqT: Equal[T], eqU: Equal[U] @@ -78,8 +77,7 @@ import Equal._; object CompatTests extends Properties("CompatTests") { import java.io._; - def compatFor[T](name: String, readJ: DataInput => T, writeJ: (DataOutput, T) => Unit)( - implicit + def compatFor[T](name: String, readJ: DataInput => T, writeJ: (DataOutput, T) => Unit)(implicit fmt: Format[T], arb: Arbitrary[T] ) = { @@ -130,30 +128,26 @@ object LazyIOTests extends Properties("LazyIO") { } object FormatTests extends Properties("Formats") { - def validFormat[T]( - implicit + def validFormat[T](implicit bin: Format[T], arb: Arbitrary[T], equal: Equal[T] ) = - forAll( - (x: T) => - try { - equal(x, fromByteArray[T](toByteArray(x))) - } catch { - case (e: Throwable) => e.printStackTrace; false - } + forAll((x: T) => + try { + equal(x, fromByteArray[T](toByteArray(x))) + } catch { + case (e: Throwable) => e.printStackTrace; false + } ) - def formatSpec[T](name: String)( - implicit + def formatSpec[T](name: String)(implicit bin: Format[T], arb: Arbitrary[T], equal: Equal[T] ) = { property(name) = validFormat[T] } - implicit def arbitrarySortedMap[K, V]( - implicit + implicit def arbitrarySortedMap[K, V](implicit ord: Ordering[K], arbK: Arbitrary[K], arbV: Arbitrary[V] @@ -161,9 +155,8 @@ object FormatTests extends Properties("Formats") { Arbitrary(arbitrary[List[(K, V)]].map(x => immutable.TreeMap(x: _*))) } - //implicit def arbitrarySet[T](implicit arb : Arbitrary[T]) : Arbitrary[immutable.Set[T]] = Arbitrary(arbitrary[List[T]].map((x : List[T]) => immutable.Set(x :_*))); - implicit def arbitraryArray[T]( - implicit + // implicit def arbitrarySet[T](implicit arb : Arbitrary[T]) : Arbitrary[immutable.Set[T]] = Arbitrary(arbitrary[List[T]].map((x : List[T]) => immutable.Set(x :_*))); + implicit def arbitraryArray[T](implicit arb: Arbitrary[T], mf: scala.reflect.Manifest[T] ): Arbitrary[Array[T]] = diff --git a/project/Fmpp.scala b/project/Fmpp.scala index fee61ce..045937a 100644 --- a/project/Fmpp.scala +++ b/project/Fmpp.scala @@ -3,7 +3,9 @@ import Keys._ object Fmpp { - /*** Templating **/ + /** + * * Templating * + */ lazy val fmpp = TaskKey[Seq[File]]("fmpp") lazy val fmppOptions = SettingKey[Seq[String]]("fmpp-options") lazy val FmppConfig = config("fmpp") hide @@ -13,11 +15,13 @@ object Fmpp { libraryDependencies += "net.sourceforge.fmpp" % "fmpp" % "0.9.16" % FmppConfig, ivyConfigurations += FmppConfig, fmppOptions := "--ignore-temporary-files" :: Nil, - FmppConfig / fullClasspath := update.value select configurationFilter(FmppConfig.name) map Attributed.blank + FmppConfig / fullClasspath := update.value select configurationFilter( + FmppConfig.name + ) map Attributed.blank ) import sbt.io.Path._ - def fmppConfig(c: Configuration): Seq[Setting[_]] = + def fmppConfig(c: Configuration): Seq[Setting[?]] = inConfig(c)( Seq( sourceGenerators += fmpp, @@ -35,7 +39,8 @@ object Fmpp { val args = fmppOptions.value val s = streams.value IO.delete(output) - val arguments = "-U" +: "all" +: "-S" +: srcRoot.getAbsolutePath +: "-O" +: output.getAbsolutePath +: (args ++ sources.getPaths) + val arguments = + "-U" +: "all" +: "-S" +: srcRoot.getAbsolutePath +: "-O" +: output.getAbsolutePath +: (args ++ sources.getPaths) r.run("fmpp.tools.CommandLine", cp.files, arguments, s.log) // .foreach(sys.error) (output ** "*.scala").get } diff --git a/project/HouseRulesPlugins.scala b/project/HouseRulesPlugins.scala index ce349ca..c7eb6b1 100644 --- a/project/HouseRulesPlugins.scala +++ b/project/HouseRulesPlugins.scala @@ -5,12 +5,12 @@ object HouseRulesPlugin extends AutoPlugin { override def requires = plugins.JvmPlugin override def trigger = allRequirements - override def buildSettings: Seq[Def.Setting[_]] = baseBuildSettings - override def projectSettings: Seq[Def.Setting[_]] = baseSettings + override def buildSettings: Seq[Def.Setting[?]] = baseBuildSettings + override def projectSettings: Seq[Def.Setting[?]] = baseSettings - lazy val baseBuildSettings: Seq[Def.Setting[_]] = Seq() + lazy val baseBuildSettings: Seq[Def.Setting[?]] = Seq() - lazy val baseSettings: Seq[Def.Setting[_]] = Seq( + lazy val baseSettings: Seq[Def.Setting[?]] = Seq( scalacOptions ++= Seq("-encoding", "utf8"), scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-Xlint"), scalacOptions += "-language:higherKinds", @@ -31,8 +31,8 @@ object HouseRulesPlugin extends AutoPlugin { scalacOptions += "-Ywarn-numeric-widen", scalacOptions += "-Ywarn-value-discard", scalacOptions ++= "-Ywarn-unused-import".ifScala(v => 11 <= v && v <= 12).value.toList - ) ++ Seq(Compile, Test).flatMap( - c => c / console / scalacOptions --= Seq("-Ywarn-unused-import", "-Xlint") + ) ++ Seq(Compile, Test).flatMap(c => + c / console / scalacOptions --= Seq("-Ywarn-unused-import", "-Xlint") ) private def scalaPartV = Def setting (CrossVersion partialVersion scalaVersion.value)