Skip to content

Commit

Permalink
Upgrade scalafmt (#186)
Browse files Browse the repository at this point in the history
* Update scalafmt and dependencies

* Remove sbtpolecat

---------

Co-authored-by: Alfredo Torre <atorre@descartes.com>
  • Loading branch information
sentenza and Alfredo Torre committed Dec 22, 2023
1 parent 947239b commit cb7eb9a
Show file tree
Hide file tree
Showing 24 changed files with 609 additions and 470 deletions.
84 changes: 72 additions & 12 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,14 +1,74 @@
# See: https://scalameta.org/scalafmt/docs/configuration.html
version = "3.7.17"

# Version https://scalameta.org/scalafmt/docs/configuration.html#version
version = 3.7.17
# Dialect https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects
runner.dialect = scala213source3
align.preset = more
style = defaultWithAlign # For pretty alignment.
maxColumn = 100
docstrings.style = SpaceAsterisk
docstrings.removeEmpty = true
continuationIndent.callSite = 2
continuationIndent.defnSite = 4

# Top-level preset https://scalameta.org/scalafmt/docs/configuration.html#top-level-presets
preset = defaultWithAlign

# Common https://scalameta.org/scalafmt/docs/configuration.html#most-popular
maxColumn = 120
assumeStandardLibraryStripMargin = true

# Alignment https://scalameta.org/scalafmt/docs/configuration.html#alignment
align {
preset = more
allowOverflow = true
}

# Newlines https://scalameta.org/scalafmt/docs/configuration.html#newlines
newlines {
alwaysBeforeMultilineDef = false
implicitParamListModifierPrefer = before
beforeCurlyLambdaParams = multilineWithCaseOnly
inInterpolation = "avoid"
}

# Comment processing https://scalameta.org/scalafmt/docs/configuration.html#comment-processing
docstrings {
style = Asterisk
wrap = no
removeEmpty = true
}

# Spaces https://scalameta.org/scalafmt/docs/configuration.html#spaces
spaces {
inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy => zzz }
}

# Project https://scalameta.org/scalafmt/docs/configuration.html#project
project {
git = true
excludeFilters = ["target/"]
}

# Rewrite Rules https://scalameta.org/scalafmt/docs/configuration.html#rewrite-rules
rewrite {
rules = [
AvoidInfix, # https://scalameta.org/scalafmt/docs/configuration.html#avoidinfix
RedundantParens, # https://scalameta.org/scalafmt/docs/configuration.html#redundantparens
SortModifiers, # https://scalameta.org/scalafmt/docs/configuration.html#sortmodifiers
PreferCurlyFors, # https://scalameta.org/scalafmt/docs/configuration.html#prefercurlyfors
Imports, # https://scalameta.org/scalafmt/docs/configuration.html#imports
]
sortModifiers.order = ["private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy"]
imports {
expand = true
sort = original
groups = [["java(x)?\\..*"], ["scala\\..*"], ["sbt\\..*"]]
}
trailingCommas.style = keep # https://scalameta.org/scalafmt/docs/configuration.html#trailing-commas
}

fileOverride {
"glob:**/src/main/scala-3/**" {
runner.dialect = scala3
}
}

includeCurlyBraceInSelectChains = false
project.git = true
project.excludeFilters = ["target/"]

continuationIndent {
callSite = 2
defnSite = 4
}
12 changes: 6 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
val ScalaTestVersion = "3.2.10"
val ScalaTestVersion = "3.2.17"
val FlexmarkVersion = "0.64.8"

scalafmtOnCompile := true
Expand All @@ -8,13 +8,13 @@ lazy val root = (project in file("."))
organization := "io.github.sentenza.hacktoberfest",
name := "hacktoberfest-algorithms",
version := "0.12.0",
scalaVersion := "2.13.8",
scalaVersion := "2.13.12",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % "2.13.12",
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"org.scalatestplus" %% "mockito-3-4" % (ScalaTestVersion + ".0") % Test,
"org.scalactic" %% "scalactic" % ScalaTestVersion % Test,
"com.vladsch.flexmark" % "flexmark-all" % FlexmarkVersion % Test
"org.scalatest" %% "scalatest" % ScalaTestVersion % Test,
"org.scalatestplus" %% "mockito-3-4" % "3.2.10.0" % Test,
"org.scalactic" %% "scalactic" % ScalaTestVersion % Test,
"com.vladsch.flexmark" % "flexmark-all" % FlexmarkVersion % Test
),
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.full),
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1")
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.8
6 changes: 0 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
// Easily manage scalac settings across scala versions with this
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.4")

// Makes our code tidy
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

// Revolver allows us to use re-start and work a lot faster!
addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0")

// To keep our dependencies up to date
addSbtPlugin("net.vonbuchholtz" % "sbt-dependency-check" % "5.1.0")

// Enables test coverage analysis
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")

Expand Down
42 changes: 24 additions & 18 deletions src/main/scala/io/github/sentenza/hacktoberfest/MenuIO.scala
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package io.github.sentenza.hacktoberfest

import System.out.println
import scala.annotation.tailrec
import scala.util.{Try, Success}
import io.github.sentenza.hacktoberfest.algos.sort.MutableSorting
import io.github.sentenza.hacktoberfest.algos.sort.ImmutableSorting
import io.github.sentenza.hacktoberfest.algos.sort.Sorting
import scala.reflect.runtime.universe._
import scala.reflect.ClassTag
import scala.util.Success
import scala.util.Try

import io.github.sentenza.hacktoberfest.algos.sort.ImmutableSorting
import io.github.sentenza.hacktoberfest.algos.sort.MutableSorting
import io.github.sentenza.hacktoberfest.algos.sort.Sorting
import System.out.println

/*
* HacktoberFest - Scala Algorithms
Expand Down Expand Up @@ -43,9 +45,10 @@ object MenuIO {
https://github.com/sentenza/hacktoberfest-scala-algorithms/blob/master/LICENSE.
"""

/** This function should be called at the very beginning of the Main execution to fetch the
* disclaimer message and the project Logo to be printed out
*/
/**
* This function should be called at the very beginning of the Main execution to fetch the
* disclaimer message and the project Logo to be printed out
*/
def printDisclaimer(): Unit = { println(heading + gplDisclaimer) }

def readNumberInputs(): Array[Int] = {
Expand Down Expand Up @@ -117,14 +120,16 @@ object MenuIO {
@tailrec
def renderInteractiveMenu(entries: List[MenuEntry] = rootEntries): Unit = {
println("Please choose:")
entries.sortBy(_.selector).foreach { case MenuEntry(num, label, _) =>
println(s"$num: $label")
entries.sortBy(_.selector).foreach {
case MenuEntry(num, label, _) =>
println(s"$num: $label")
}

Try(scala.io.StdIn.readInt()) match {
case Success(choice) if entries.exists(_.selector == choice) =>
entries.find(_.selector == choice).foreach { case MenuEntry(_, _, code) =>
code()
entries.find(_.selector == choice).foreach {
case MenuEntry(_, _, code) =>
code()
}
renderInteractiveMenu()
case _ =>
Expand All @@ -139,12 +144,13 @@ object MenuIO {
)(implicit show: Show[F[T]], ftt: TypeTag[F[T]]) = {

val (_, entries) = collectSortMethods[S, F[T]](sorting)
.foldLeft(1 -> List.empty[MenuEntry]) { case ((count, entries), (sortName, sortFunction)) =>
count + 1 -> (entries :+ MenuEntry(
count,
sortName,
() => executeSort(sortName, sortFunction, toSort)
))
.foldLeft(1 -> List.empty[MenuEntry]) {
case ((count, entries), (sortName, sortFunction)) =>
count + 1 -> (entries :+ MenuEntry(
count,
sortName,
() => executeSort(sortName, sortFunction, toSort)
))
}

entries
Expand Down
112 changes: 61 additions & 51 deletions src/main/scala/io/github/sentenza/hacktoberfest/adt/Queue.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ package io.github.sentenza.hacktoberfest.adt
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

/** Functional Queue Defines the generic type {{{Queue[T]}}}
*
* @see
* Programming in Scala (2nd edition) Ch. 19.7 Note that Queue is covariant in T
* [[https://sentenza.github.io/docs/scala/#variance Read about variance]] A *fully persistent*
* data structure with three operations:
* - head: returns the first element of the queue
* - tail: returns a queue without the first element
* - enqueue: returns a NEW queue with a given element appended to the end
*/
/**
* Functional Queue Defines the generic type {{{Queue[T]}}}
*
* @see
* Programming in Scala (2nd edition) Ch. 19.7 Note that Queue is covariant in T
* [[https://sentenza.github.io/docs/scala/#variance Read about variance]] A *fully persistent*
* data structure with three operations:
* - head: returns the first element of the queue
* - tail: returns a queue without the first element
* - enqueue: returns a NEW queue with a given element appended to the end
*/
trait Queue[+T] {

/** @return The first element of the queue */
Expand All @@ -33,66 +34,74 @@ trait Queue[+T] {
/** @return A queue without the first element */
def tail: Queue[T]

/** Appends and element x to the end of the queue
* @param x
* The element to be appended to the end
* @tparam U
* We need to define T as the LOWER BOUND of U, because the type of the function parameters
* must be in contravariant position
* @return
* A new queue containing x at its end
*/
/**
* Appends and element x to the end of the queue
* @param x
* The element to be appended to the end
* @tparam U
* We need to define T as the LOWER BOUND of U, because the type of the function parameters
* must be in contravariant position
* @return
* A new queue containing x at its end
*/
def enqueue[U >: T](x: U): Queue[U]

/** Converts the queue in a List
*/
/**
* Converts the queue in a List
*/
def toList: List[T]

/** @param other
* Another Queue
*/
/**
* @param other
* Another Queue
*/
def equals[U >: T](other: Queue[U]): Boolean

/** @return
* True if the queue is empty
*/
/**
* @return
* True if the queue is empty
*/
def isEmpty: Boolean

/** !Queue.isEmtpy()
*/
/**
* !Queue.isEmtpy()
*/
def nonEmpty: Boolean

def size: Int

override def toString: String
}

/** The companion object Queue.
* @example
* {{{Queue(13, 21, 34, 55, 89, 144)}}}
*/
/**
* The companion object Queue.
* @example
* {{{Queue(13, 21, 34, 55, 89, 144)}}}
*/
object Queue {

/** Factory method */
def apply[T](xs: T*): Queue[T] =
new QueueImpl[T](xs.toList, Nil)

/** This queue is still a pure functional object, even though we're using INTERNALLY reassignable
* immutable fields
* @param leading
* The start fo the queue
* @param trailing
* The end of the queue
*/
/**
* This queue is still a pure functional object, even though we're using INTERNALLY reassignable
* immutable fields
* @param leading
* The start fo the queue
* @param trailing
* The end of the queue
*/
private class QueueImpl[+T](
private[this] var leading: List[T],
private[this] var trailing: List[T]
) extends Queue[T] {

/** This is an impure function but we need it in order to minimise the complexity of reversing
* an immutable list and then copying across all the elements to have at each moment: queue =
* leading ::: (trailing.reverse)
*/
/**
* This is an impure function but we need it in order to minimise the complexity of reversing
* an immutable list and then copying across all the elements to have at each moment: queue =
* leading ::: (trailing.reverse)
*/
private def mirror(): Unit =
if (leading.isEmpty) {
while (trailing.nonEmpty) {
Expand Down Expand Up @@ -136,13 +145,14 @@ object Queue {
def size: Int =
leading.size + trailing.size

/** @param separator
* The String separator (e.g. ",", ":"
* @param l
* The leading list
* @param t
* The trailing list
*/
/**
* @param separator
* The String separator (e.g. ",", ":"
* @param l
* The leading list
* @param t
* The trailing list
*/
private def buildPrint[U >: T](separator: String)(l: List[U])(t: List[U]): String = t match {
case Nil => l.mkString("Queue(", separator, ")")
case _ => {
Expand Down
Loading

0 comments on commit cb7eb9a

Please sign in to comment.