Skip to content

Commit c8c97a4

Browse files
authored
Upgrade to Scala 3.3.7 (#5)
* Upgrade to Scala 3.3.7 - Change scalaVersion from 2.13.18 to 3.3.7 - Rewrite Cell as a Scala 3 enum - Replace implicit vals/defs with given instances - Replace implicit conversions with given Conversion - Update wildcard imports from _ to * syntax - Replace deprecated private[this] with private - Remove @nowarn annotations on case classes (no longer needed in Scala 3) - Add @unchecked to irrefutable pattern match - Remove Scala 3-incompatible scalafix rules (RemoveUnused, LeakingImplicitClassVal, NoAutoTupling) - Remove semanticdbVersion override (built-in in Scala 3) * gitignore * Fix Release Drafter failing on pull requests disable-releaser on PR events to prevent invalid target_commitish error. Also fix branch name from main to master. * Fix Release Drafter: only run on push to master Remove pull_request trigger that caused invalid target_commitish errors.
1 parent 965bf04 commit c8c97a4

8 files changed

Lines changed: 30 additions & 39 deletions

File tree

.github/workflows/draft.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ name: Release Drafter
33
on:
44
push:
55
branches:
6-
- main
7-
8-
pull_request:
9-
types: [opened, reopened, synchronize]
6+
- master
107

118
permissions:
129
contents: read

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,5 @@ fabric.properties
7676
# Editor-based Rest Client
7777
.idea/httpRequests
7878
### Scala template
79+
80+
.bsp

.scalafix.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
rules = [
22
DisableSyntax
3-
// ExplicitResultTypes // Waiting for: https://github.com/scalacenter/scalafix/issues/1583
4-
LeakingImplicitClassVal
5-
NoAutoTupling
63
NoValInForComprehension
74
OrganizeImports
8-
RemoveUnused
95
RedundantSyntax
106
]
117

build.sbt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import BuildHelper.*
22

33
ThisBuild / organization := "com.guizmaii"
4-
ThisBuild / scalaVersion := "2.13.18"
4+
ThisBuild / scalaVersion := "3.3.7"
55

66
ThisBuild / scalafmtCheck := true
77
ThisBuild / scalafmtSbtCheck := true
88
ThisBuild / scalafmtOnCompile := !insideCI.value
99
ThisBuild / semanticdbEnabled := true
10-
ThisBuild / semanticdbVersion := scalafixSemanticdb.revision // use Scalafix compatible version
1110

1211
ThisBuild / licenses := Seq("MIT" -> url("https://opensource.org/licenses/MIT"))
1312
ThisBuild / homepage := Some(url("https://github.com/guizmaii-opensource/JRubyConcurrentConstantMemoryExcel"))

core/src/main/scala/com/colisweb/jruby/concurrent/constant/memory/excel/ConcurrentConstantMemoryExcel.scala

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,31 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook
1313
import java.io.{File, FileOutputStream}
1414
import java.nio.file.{Files, Path}
1515
import java.util.UUID
16-
import scala.annotation.{nowarn, switch}
16+
import scala.annotation.switch
1717
import scala.collection.immutable.SortedSet
1818
import scala.collection.mutable.ListBuffer
1919
import scala.io.Codec
2020

21-
sealed abstract class Cell extends Product with Serializable
22-
object Cell {
23-
private[excel] case object BlankCell extends Cell
24-
private[excel] final case class StringCell(value: String) extends Cell
25-
private[excel] final case class NumericCell(value: Double) extends Cell
21+
enum Cell {
22+
case BlankCell
23+
case StringCell(value: String)
24+
case NumericCell(value: Double)
25+
}
2626

27+
object Cell {
2728
private[excel] final val BLANK_CELL = 'b'
2829
private[excel] final val STRING_CELL = 's'
2930
private[excel] final val NUMERIC_CELL = 'n'
3031

31-
implicit private[excel] final val encoder: CellEncoder[Cell] = {
32+
private[excel] given CellEncoder[Cell] = {
3233
case BlankCell => s"$BLANK_CELL:"
3334
case StringCell(value) => s"$STRING_CELL:$value"
3435
case NumericCell(value) => s"$NUMERIC_CELL:$value"
3536
}
3637

37-
implicit private[excel] final val decoder: CellDecoder[Cell] =
38+
private[excel] given CellDecoder[Cell] =
3839
CellDecoder.fromUnsafe { s =>
39-
val Array(cellType, data) = s.split(":", 2)
40+
val Array(cellType, data) = s.split(":", 2): @unchecked
4041
(cellType(0): @switch) match {
4142
case BLANK_CELL => Cell.BlankCell
4243
case STRING_CELL => Cell.StringCell(data)
@@ -45,13 +46,11 @@ object Cell {
4546
}
4647
}
4748

48-
@nowarn // TODO: Remove this nowarm when upgrading to Scala3
4949
final case class Page private[excel] (index: Int, path: Path)
5050
private[excel] object Page {
51-
implicit final val ordering: Ordering[Page] = Ordering.by(_.index)
51+
given Ordering[Page] = Ordering.by(_.index)
5252
}
5353

54-
@nowarn // TODO: Remove this nowarm when upgrading to Scala3
5554
final case class ConcurrentConstantMemoryState private[excel] (
5655
sheetName: String,
5756
headerData: Array[String],
@@ -62,16 +61,15 @@ final case class ConcurrentConstantMemoryState private[excel] (
6261

6362
object ConcurrentConstantMemoryExcel {
6463

65-
import kantan.csv._
66-
import kantan.csv.ops._
64+
import kantan.csv.*
65+
import kantan.csv.ops.*
6766
// https://nrinaudo.github.io/kantan.csv/bom.html
68-
import kantan.codecs.resource.bom._
67+
import kantan.codecs.resource.bom.*
6968

7069
private[excel] type Row = Array[Cell]
7170

72-
implicit private[this] final val codec: Codec = Codec.UTF8
73-
implicit private[this] final val scheduler: Scheduler =
74-
Scheduler.computation(name = "ConcurrentConstantMemoryExcel-computation")
71+
private given Codec = Codec.UTF8
72+
private given Scheduler = Scheduler.computation(name = "ConcurrentConstantMemoryExcel-computation")
7573

7674
final val blankCell: Cell = Cell.BlankCell
7775

@@ -150,7 +148,7 @@ object ConcurrentConstantMemoryExcel {
150148

151149
// TODO: Expose the `swallowIOExceptions` parameter in the `writeFile` function ?
152150
def clean(swallowIOExceptions: Boolean = false): Task[Unit] = Task {
153-
import better.files._ // better-files `delete()` method also works on directories, unlike the Java one.
151+
import better.files.* // better-files `delete()` method also works on directories, unlike the Java one.
154152
cms.tmpDirectory.toScala.delete(swallowIOExceptions)
155153
()
156154
}

core/src/main/scala/com/colisweb/jruby/concurrent/constant/memory/excel/utils/KantanExtension.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.collection.immutable.ArraySeq
66

77
private[excel] object KantanExtension {
88

9-
implicit final def arrayEncoder[A](implicit CellEncoder: CellEncoder[A]): RowEncoder[Array[A]] =
10-
(array: Array[A]) => ArraySeq.unsafeWrapArray(array).map(CellEncoder.encode)
9+
given arrayEncoder[A](using cellEncoder: CellEncoder[A]): RowEncoder[Array[A]] =
10+
(array: Array[A]) => ArraySeq.unsafeWrapArray(array).map(cellEncoder.encode)
1111

1212
}

core/src/test/scala/com/colisweb/jruby/concurrent/constant/memory/excel/ConcurrentConstantMemoryExcelSpec.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.io.File
88
import java.nio.file.Files
99
import java.util.Date
1010
import scala.annotation.nowarn
11+
import scala.language.implicitConversions
1112

1213
@nowarn("msg=unused value")
1314
class ConcurrentConstantMemoryExcelSpec extends AnyFlatSpec with Matchers {
@@ -16,14 +17,15 @@ class ConcurrentConstantMemoryExcelSpec extends AnyFlatSpec with Matchers {
1617
true shouldBe true
1718
}
1819

19-
import ConcurrentConstantMemoryExcel._
20+
import ConcurrentConstantMemoryExcel.*
2021

2122
val sheet_name = "SHEET_NAME"
2223
val headers = Array("A", "B", "C")
2324

2425
// Ugly but handy. Don't abuse of that !
25-
implicit final def toCell(value: String): Cell = if (value.isEmpty) blankCell else stringCell(value)
26-
implicit final def toCell(value: Double): Cell = numericCell(value)
26+
given Conversion[String, Cell] = value => if (value.isEmpty) blankCell else stringCell(value)
27+
given Conversion[Double, Cell] = value => numericCell(value)
28+
given Conversion[Int, Cell] = value => numericCell(value.toDouble)
2729

2830
def newCMSPlz: Atomic[ConcurrentConstantMemoryState] = newWorkbookState(sheet_name, headers)
2931
def row(cells: Cell*): Array[Cell] = cells.toArray

project/BuildHelper.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@ object BuildHelper {
1313
lazy val stdSettings =
1414
Seq(
1515
javacOptions ++= Seq("-source", javaTarget, "-target", javaTarget),
16-
scalacOptions ++= Seq("-Xsource:3"), // TODO: Remove when upgrading to Scala3
17-
// TODO: Re-enable when upgrading to Scala3
18-
// scalacOptions ++= Seq("-no-indent"), // See https://x.com/ghostdogpr/status/1706589471469425074
19-
// TODO: Re-enable when upgrading to Scala3
20-
// scalacOptions ++= Seq("-language:noAutoTupling"), // See https://github.com/scala/scala3/discussions/19255
16+
scalacOptions ++= Seq("-no-indent"), // See https://x.com/ghostdogpr/status/1706589471469425074
17+
scalacOptions ++= Seq("-language:noAutoTupling"), // See https://github.com/scala/scala3/discussions/19255
2118
scalacOptions ++= Seq(s"-release:$javaTarget"),
2219
scalacOptions --= (if (insideCI.value) Nil else Seq("-Xfatal-warnings")),
2320
// format: off

0 commit comments

Comments
 (0)