From 99a40dbc3206e7c07faa31a702411375bdfcf09c Mon Sep 17 00:00:00 2001 From: q-guidomaresca Date: Thu, 19 Sep 2024 19:04:05 +0200 Subject: [PATCH] Added sbt-tpolecat compiler plugin --- build.sbt | 19 ++-- .../scala/figlet4s/FigletBenchmark.scala | 8 +- .../figlet4s/unsafe/UnsafeFiglet4sSpecs.scala | 18 ++-- .../figlet4s/JavaOptionsBuilderSpecs.scala | 1 - project/Compiler.scala | 88 ------------------- project/project/Plugins.scala | 7 +- 6 files changed, 29 insertions(+), 112 deletions(-) diff --git a/build.sbt b/build.sbt index 7fd9ee7..edb000f 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ -import sbt._ import Dependencies._ import TestDependencies._ +import sbt._ import utils._ import xerial.sbt.Sonatype._ @@ -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 @@ -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( diff --git a/figlet4s-benchmarks/src/test/scala/com/colofabrix/scala/figlet4s/FigletBenchmark.scala b/figlet4s-benchmarks/src/test/scala/com/colofabrix/scala/figlet4s/FigletBenchmark.scala index 3d0d6a6..b3d8279 100644 --- a/figlet4s-benchmarks/src/test/scala/com/colofabrix/scala/figlet4s/FigletBenchmark.scala +++ b/figlet4s-benchmarks/src/test/scala/com/colofabrix/scala/figlet4s/FigletBenchmark.scala @@ -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) } diff --git a/figlet4s-core/src/it/scala/com/colofabrix/scala/figlet4s/unsafe/UnsafeFiglet4sSpecs.scala b/figlet4s-core/src/it/scala/com/colofabrix/scala/figlet4s/unsafe/UnsafeFiglet4sSpecs.scala index 1c462a0..417ae65 100644 --- a/figlet4s-core/src/it/scala/com/colofabrix/scala/figlet4s/unsafe/UnsafeFiglet4sSpecs.scala +++ b/figlet4s-core/src/it/scala/com/colofabrix/scala/figlet4s/unsafe/UnsafeFiglet4sSpecs.scala @@ -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 @@ -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 } @@ -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 @@ -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 // @@ -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, ) diff --git a/figlet4s-java/src/test/scala/com/colofabrix/java/figlet4s/JavaOptionsBuilderSpecs.scala b/figlet4s-java/src/test/scala/com/colofabrix/java/figlet4s/JavaOptionsBuilderSpecs.scala index 48e23ba..a0a1065 100644 --- a/figlet4s-java/src/test/scala/com/colofabrix/java/figlet4s/JavaOptionsBuilderSpecs.scala +++ b/figlet4s-java/src/test/scala/com/colofabrix/java/figlet4s/JavaOptionsBuilderSpecs.scala @@ -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._ diff --git a/project/Compiler.scala b/project/Compiler.scala index 53acf8f..5e69ad7 100644 --- a/project/Compiler.scala +++ b/project/Compiler.scala @@ -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 @@ -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" diff --git a/project/project/Plugins.scala b/project/project/Plugins.scala index 57cb3f4..6908b0a 100644 --- a/project/project/Plugins.scala +++ b/project/project/Plugins.scala @@ -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, )