Skip to content

Commit

Permalink
Added sbt-tpolecat compiler plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
q-guidomaresca committed Sep 19, 2024
1 parent 798bde0 commit 99a40db
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 112 deletions.
19 changes: 11 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sbt._
import Dependencies._
import TestDependencies._
import sbt._
import utils._
import xerial.sbt.Sonatype._

Expand Down Expand Up @@ -53,15 +53,15 @@ val commonScalaSettings: Seq[Def.Setting[_]] = Seq(
Test / testOptions += Tests.Argument("-oFD"),
// Compiler options
scalacOptions := versioned(scalaVersion.value)(
Compiler.Options_2_12 ++ Compiler.StrictOptions,
Compiler.Options_2_13 ++ Compiler.StrictOptions,
Seq.empty,
Compiler.Options_2_13,
),
Test / scalacOptions := versioned(scalaVersion.value)(
Compiler.Options_2_12,
Seq.empty,
Compiler.Options_2_13,
),
IntegrationTest / scalacOptions := versioned(scalaVersion.value)(
Compiler.Options_2_12,
Seq.empty,
Compiler.Options_2_13,
),
// Cross Scala Versions
Expand All @@ -80,9 +80,12 @@ val commonScalaSettings: Seq[Def.Setting[_]] = Seq(
// Scaladoc
Compile / autoAPIMappings := true,
Compile / doc / scalacOptions ++= Seq(
"-doc-title", "Figlet4s API Documentation",
"-doc-version", version.value,
"-encoding", "UTF-8",
"-doc-title",
"Figlet4s API Documentation",
"-doc-version",
version.value,
"-encoding",
"UTF-8",
),
// Packaging and publishing
Compile / packageBin / packageOptions ++= Seq(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ abstract class FigletBenchmark extends Bench[Double] {
def persistor: Persistor =
new persistence.GZIPJSONSerializationPersistor

override def reporter: Reporter[Double] =
LoggingReporter()
private def historian: RegressionReporter.Historian =
RegressionReporter.Historian.ExponentialBackoff()

private def tester: RegressionReporter.Tester =
RegressionReporter.Tester.Accepter()

private def historian: RegressionReporter.Historian =
RegressionReporter.Historian.ExponentialBackoff()
override def reporter: Reporter[Double] =
RegressionReporter(tester, historian)
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class UnsafeFiglet4sSpecs extends AnyFlatSpec with Matchers with Figlet4sMatcher
computed should lookLike(expected)
}

it should "render the texts as the original command line FIGlet does" taggedAs (SlowTest) in {
it should "render the texts as the original command line FIGlet does" taggedAs SlowTest in {
figletRenderingTest { testData =>
val testBuilder =
Figlet4s
Expand All @@ -50,7 +50,7 @@ class UnsafeFiglet4sSpecs extends AnyFlatSpec with Matchers with Figlet4sMatcher

it should "list the correct number of fonts" in {
val actual = Figlet4s.internalFonts.length
val expected = 380
val expected = 380 //It's 453 on macOS Sonoma
actual shouldBe expected
}

Expand Down Expand Up @@ -95,8 +95,7 @@ class UnsafeFiglet4sSpecs extends AnyFlatSpec with Matchers with Figlet4sMatcher
val subdirPathRegex = s"^$subdir\\$pathSeparator.*".r
Figlet4s
.internalFonts
.filter(subdirPathRegex.findFirstIn(_).isDefined)
.length
.count(subdirPathRegex.findFirstIn(_).isDefined)
}

actual should contain theSameElementsInOrderAs expected
Expand Down Expand Up @@ -136,28 +135,28 @@ class UnsafeFiglet4sSpecs extends AnyFlatSpec with Matchers with Figlet4sMatcher
}

it should "load a font file" in {
val fontPath = getClass.getResource("/raw.flf").getPath()
val fontPath = getClass.getResource("/raw.flf").getPath
Figlet4s.loadFont(fontPath)
}

it should "load a zipped font file" in {
val fontPath = getClass.getResource("/compressed.flf").getPath()
val fontPath = getClass.getResource("/compressed.flf").getPath
Figlet4s.loadFont(fontPath)
}

it should "use the first added file in a zipped font file" in {
val fontPath = getClass.getResource("/multiple.flf").getPath()
val fontPath = getClass.getResource("/multiple.flf").getPath
val font = Figlet4s.loadFont(fontPath)
font.comment should include("Standard by Glenn Chappell & Ian Chai")
}

it should "error on an empty zipped font file" in {
val fontPath = getClass.getResource("/empty.flf").getPath()
val fontPath = getClass.getResource("/empty.flf").getPath
val caught =
intercept[FigletLoadingError] {
Figlet4s.loadFont(fontPath)
}
caught.getMessage() shouldBe "Cannot read font file from ZIP"
caught.getMessage shouldBe "Cannot read font file from ZIP"
}

// Fonts //
Expand Down Expand Up @@ -199,6 +198,7 @@ class UnsafeFiglet4sSpecs extends AnyFlatSpec with Matchers with Figlet4sMatcher

private lazy val fontsSubdirectories: Map[String, Int] =
Map(
//"bdffonts" -> 73, //This is required on macOS Sonoma
"c64" -> 186,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.colofabrix.java.figlet4s

import com.colofabrix.java.figlet4s.options._
import com.colofabrix.scala.figlet4s.testutils._
import org.scalatest.flatspec._
import org.scalatest.matchers.should._

Expand Down
88 changes: 0 additions & 88 deletions project/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,7 @@ object Compiler {
private lazy val cores = java.lang.Runtime.getRuntime.availableProcessors

// Compiler options for Scala 2.13
// https://nathankleyn.com/2019/05/13/recommended-scalac-flags-for-2-13/
lazy val Options_2_13: Seq[String] = Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard", // Warn when non-Unit expression results are unused.
"-Ymacro-annotations", // Enable macro annotations
"-Ybackend-parallelism", cores.toString, // Enable paralellisation
"-Ycache-plugin-class-loader:last-modified", // Enables caching of classloaders for compiler plugins
Expand All @@ -48,60 +14,6 @@ object Compiler {
"-Xnon-strict-patmat-analysis" // Excessive strictness introduced with Scala 2.13.4 creates issues
)

// Compiler options for Scala 2.12
// https://tpolecat.github.io/2017/04/25/scalac-flags.html
lazy val Options_2_12: Seq[String] = Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", "utf-8", // Specify character encoding used by source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfuture", // Turn on future language features.
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:by-name-right-associative", // By-name parameter of right associative operator.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xlint:unsound-match", // Pattern match may not be typesafe.
"-Yno-adapted-args", // Do not adapt an argument list (either by inserting () or creating a tuple) to match the receiver.
"-Ypartial-unification", // Enable partial unification in type constructor inference
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-inaccessible", // Warn about inaccessible types in method signatures.
"-Ywarn-infer-any", // Warn when a type argument is inferred to be `Any`.
"-Ywarn-nullary-override", // Warn when non-nullary `def f()' overrides nullary `def f'.
"-Ywarn-nullary-unit", // Warn when nullary methods return Unit.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates", // Warn if a private member is unused.
"-Ywarn-value-discard" // Warn when non-Unit expression results are unused.
)

// Stricter compile option to filter out in specific situation
lazy val StrictOptions: Seq[String] = Seq(
"-Xfatal-warnings", // Fail the compilation if there are any warning.
)

// Options for the Splain plugin
lazy val SplainOptions: Seq[String] = Seq(
"-P:splain:all"
Expand Down
7 changes: 5 additions & 2 deletions project/project/Plugins.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ object Plugins {
lazy val ErrorsSummaryVersion = "0.6.5"
lazy val MicrositesVersion = "1.3.4"
lazy val SbtStatsVersion = "1.0.7"
lazy val SbtTPoleCatVersion = "0.5.2"
lazy val UnidocVersion = "0.4.3"
lazy val UpdatesVersion = "0.5.3"

lazy val ErrorsSummaryDep = "com.github.duhemm" % "sbt-errors-summary" % ErrorsSummaryVersion
lazy val MicrositesDep = "com.47deg" % "sbt-microsites" % MicrositesVersion
lazy val SbtStatsDep = "com.orrsella" % "sbt-stats" % SbtStatsVersion
lazy val SbtTPoleCatDep = "org.typelevel" % "sbt-tpolecat" % SbtTPoleCatVersion
lazy val UnidocDep = "com.eed3si9n" % "sbt-unidoc" % UnidocVersion
lazy val UpdatesDep = "com.timushev.sbt" % "sbt-updates" % UpdatesVersion

lazy val sbtPlugins = Seq(
lazy val sbtPlugins: Seq[ModuleID] = Seq(
ErrorsSummaryDep,
SbtStatsDep,
MicrositesDep,
SbtStatsDep,
SbtTPoleCatDep,
UnidocDep,
UpdatesDep,
)
Expand Down

0 comments on commit 99a40db

Please sign in to comment.