diff --git a/.scalafmt.conf b/.scalafmt.conf index fcadd98d..e8563baf 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,4 +1,4 @@ -version = 3.9.4 +version = 3.9.8 project.layout = StandardConvention runner.dialect = scala3 maxColumn = 100 diff --git a/CLAUDE.md b/CLAUDE.md index e01643b5..2e72e982 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -13,7 +13,7 @@ MessagePack-Java is a binary serialization library that provides a fast and comp ### Build and Compile ```bash ./sbt compile # Compile source code -./sbt test:compile # Compile source and test code +./sbt "Test / compile" # Compile source and test code ./sbt package # Create JAR files ``` @@ -31,7 +31,7 @@ MessagePack-Java is a binary serialization library that provides a fast and comp ### Code Quality ```bash ./sbt jcheckStyle # Run checkstyle (Facebook Presto style) -./sbt scalafmtAll # Format Scala test code +./sbt scalafmtAll # Format all Scala and sbt code ``` ### Publishing @@ -66,7 +66,7 @@ The msgpack-jackson module provides: - Extension type support including timestamps ### Testing Structure -- **msgpack-core tests**: Written in Scala using AirSpec framework +- **msgpack-core tests**: Written in Scala (always use the latest Scala 3 version) using AirSpec framework - Location: `msgpack-core/src/test/scala/` - **msgpack-jackson tests**: Written in Java using JUnit - Location: `msgpack-jackson/src/test/java/` @@ -81,7 +81,7 @@ For JDK 17+ compatibility, these options are automatically added: ## Code Style Requirements - Java code follows Facebook Presto style (enforced by checkstyle) -- Scala test code uses Scalafmt with 180 character line limit +- Scala test code uses Scalafmt with Scala 3 dialect and 100 character line limit - Checkstyle runs automatically during compilation - No external dependencies allowed in msgpack-core diff --git a/README.md b/README.md index 34a3f277..54d1877a 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ msgpack-java uses [sbt](http://www.scala-sbt.org/) for building the projects. Fo Coding style * msgpack-java uses [the same coding style](https://github.com/airlift/codestyle) with Facebook Presto * [IntelliJ setting file](https://raw.githubusercontent.com/airlift/codestyle/master/IntelliJIdea14/Airlift.xml) + * Scala test code uses Scalafmt with Scala 3 dialect (always use the latest Scala 3 version) ### Basic sbt commands Enter the sbt console: @@ -76,14 +77,14 @@ $ ./sbt Here is a list of sbt commands for daily development: ``` > ~compile # Compile source codes -> ~test:compile # Compile both source and test codes +> ~"Test / compile" # Compile both source and test codes > ~test # Run tests upon source code change > ~testOnly *MessagePackTest # Run tests in the specified class > ~testOnly *MessagePackTest -- (pattern) # Run tests matching the pattern > project msgpack-core # Focus on a specific project > package # Create a jar file in the target folder of each project > jcheckStyle # Run check style -> scalafmtAll # Reformat code +> scalafmtAll # Format all Scala and sbt code ``` ### Publishing diff --git a/msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala b/msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala index 0a4328d8..b5541393 100644 --- a/msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala +++ b/msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala @@ -376,7 +376,7 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark: test("report errors when packing/unpacking malformed strings") { pending("We need to produce malformed utf-8 strings in Java 8") // Create 100 malformed UTF8 Strings - val r = new Random(0) + val r = new Random(0) val malformedStrings = Iterator .continually { val b = new Array[Byte](10) @@ -580,12 +580,12 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark: kvs .grouped(2) - .map((kvp: Array[Value]) => + .map { (kvp: Array[Value]) => val k = kvp(0) val v = kvp(1) (k.asStringValue().asString, v.asStringValue().asString) - ) + } .toMap } .toList diff --git a/msgpack-core/src/test/scala/org/msgpack/core/MessagePackerTest.scala b/msgpack-core/src/test/scala/org/msgpack/core/MessagePackerTest.scala index c1b4b0a4..7ff5d82e 100644 --- a/msgpack-core/src/test/scala/org/msgpack/core/MessagePackerTest.scala +++ b/msgpack-core/src/test/scala/org/msgpack/core/MessagePackerTest.scala @@ -211,7 +211,7 @@ class MessagePackerTest extends AirSpec with Benchmark: } test("compute totalWrittenBytes") { - val out = new ByteArrayOutputStream + val out = new ByteArrayOutputStream val packerTotalWrittenBytes = withResource(MessagePack.newDefaultPacker(out)) { packer => packer diff --git a/msgpack-core/src/test/scala/org/msgpack/core/MessageUnpackerTest.scala b/msgpack-core/src/test/scala/org/msgpack/core/MessageUnpackerTest.scala index ae25d284..adab4708 100644 --- a/msgpack-core/src/test/scala/org/msgpack/core/MessageUnpackerTest.scala +++ b/msgpack-core/src/test/scala/org/msgpack/core/MessageUnpackerTest.scala @@ -30,7 +30,7 @@ import scala.util.Random object MessageUnpackerTest: class SplitMessageBufferInput(array: Array[Array[Byte]]) extends MessageBufferInput: - var cursor = 0 + var cursor = 0 override def next(): MessageBuffer = if cursor < array.length then val a = array(cursor) @@ -45,7 +45,7 @@ import org.msgpack.core.MessageUnpackerTest.* class MessageUnpackerTest extends AirSpec with Benchmark: - private val universal = MessageBuffer.allocate(0).isInstanceOf[MessageBufferU] + private val universal = MessageBuffer.allocate(0).isInstanceOf[MessageBufferU] private def testData: Array[Byte] = val out = new ByteArrayOutputStream() val packer = MessagePack.newDefaultPacker(out) @@ -435,7 +435,7 @@ class MessageUnpackerTest extends AirSpec with Benchmark: val t = time("skip performance", repeat = N) { block("v6") { - val v6 = new org.msgpack.MessagePack() + val v6 = new org.msgpack.MessagePack() val unpacker = new org.msgpack.unpacker.MessagePackUnpacker(v6, new ByteArrayInputStream(data)) var count = 0 @@ -567,7 +567,7 @@ class MessageUnpackerTest extends AirSpec with Benchmark: val t = time("unpack performance", repeat = N) { block("v6") { - val v6 = new org.msgpack.MessagePack() + val v6 = new org.msgpack.MessagePack() val unpacker = new org.msgpack.unpacker.MessagePackUnpacker(v6, new ByteArrayInputStream(data)) var count = 0 @@ -655,7 +655,7 @@ class MessageUnpackerTest extends AirSpec with Benchmark: time("unpackBinary", repeat = 100) { block("v6") { - val v6 = new org.msgpack.MessagePack() + val v6 = new org.msgpack.MessagePack() val unpacker = new org.msgpack.unpacker.MessagePackUnpacker(v6, new ByteArrayInputStream(b)) var i = 0 diff --git a/msgpack-core/src/test/scala/org/msgpack/value/VariableTest.scala b/msgpack-core/src/test/scala/org/msgpack/value/VariableTest.scala index 4eabdbd7..2f3cbf9c 100644 --- a/msgpack-core/src/test/scala/org/msgpack/value/VariableTest.scala +++ b/msgpack-core/src/test/scala/org/msgpack/value/VariableTest.scala @@ -181,39 +181,39 @@ class VariableTest extends AirSpec with PropertyCheck: test("read integers") { forAll { (i: Int) => - check( - _.packInt(i), - checker = - v => - val iv = validateValue(v.asIntegerValue(), asInteger = true) - iv.asInt() shouldBe i - iv.asLong() shouldBe i.toLong - ) + check( + _.packInt(i), + checker = + v => + val iv = validateValue(v.asIntegerValue(), asInteger = true) + iv.asInt() shouldBe i + iv.asLong() shouldBe i.toLong + ) } } test("read double") { forAll { (x: Double) => - check( - _.packDouble(x), - checker = - v => - val iv = validateValue(v.asFloatValue(), asFloat = true) - // iv.toDouble shouldBe v - // iv.toFloat shouldBe x.toFloat - ) + check( + _.packDouble(x), + checker = + v => + val iv = validateValue(v.asFloatValue(), asFloat = true) + // iv.toDouble shouldBe v + // iv.toFloat shouldBe x.toFloat + ) } } test("read boolean") { forAll { (x: Boolean) => - check( - _.packBoolean(x), - checker = - v => - val iv = validateValue(v.asBooleanValue(), asBoolean = true) - iv.getBoolean shouldBe x - ) + check( + _.packBoolean(x), + checker = + v => + val iv = validateValue(v.asBooleanValue(), asBoolean = true) + iv.getBoolean shouldBe x + ) } } @@ -234,13 +234,13 @@ class VariableTest extends AirSpec with PropertyCheck: test("read string") { forAll { (x: String) => - check( - _.packString(x), - checker = - v => - val iv = validateValue(v.asStringValue(), asString = true) - iv.asString() shouldBe x - ) + check( + _.packString(x), + checker = + v => + val iv = validateValue(v.asStringValue(), asString = true) + iv.asString() shouldBe x + ) } } @@ -280,7 +280,7 @@ class VariableTest extends AirSpec with PropertyCheck: }, checker = v => - val iv = validateValue(v.asMapValue(), asMap = true) + val iv = validateValue(v.asMapValue(), asMap = true) val lst = iv.map() .asScala @@ -293,15 +293,15 @@ class VariableTest extends AirSpec with PropertyCheck: test("read timestamps") { forAll { (millis: Long) => - val i = Instant.ofEpochMilli(millis) - check( - _.packTimestamp(i), - checker = - v => - val ts = validateValue(v.asTimestampValue(), asTimestamp = true) - ts.isTimestampValue shouldBe true - ts.toInstant shouldBe i - ) + val i = Instant.ofEpochMilli(millis) + check( + _.packTimestamp(i), + checker = + v => + val ts = validateValue(v.asTimestampValue(), asTimestamp = true) + ts.isTimestampValue shouldBe true + ts.toInstant shouldBe i + ) } } }