Skip to content

Commit

Permalink
sbt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Oct 7, 2024
1 parent 1c3c8fe commit fd37a52
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
uses: coursier/cache-action@v6
- name: Build and test
run: |
sbt -v clean scalafmt::test test:scalafmt::test sbt:scalafmt::test test scripted
sbt -v clean scalafmtSbtCheck "+ scalafmtCheckAll" "+ test" "+ scripted"
rm -rf "$HOME/.ivy2/local" || true
find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
Expand Down
20 changes: 14 additions & 6 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
version = 2.3.2
edition = 2019-10
version = 3.8.3
maxColumn = 100
project.git = true
lineEndings = preserve

# https://docs.scala-lang.org/style/scaladoc.html recommends the JavaDoc style.
# scala/scala is written that way too https://github.com/scala/scala/blob/v2.12.2/src/library/scala/Predef.scala
docstrings = JavaDoc
docstrings.style = Asterisk

# This also seems more idiomatic to include whitespace in import x.{ yyy }
spaces.inImportCurlyBraces = true
Expand All @@ -16,7 +15,16 @@ spaces.inImportCurlyBraces = true
align.openParenCallSite = false
align.openParenDefnSite = false

# For better code clarity
danglingParentheses = true

trailingCommas = preserve

align.preset = none
align.tokens = [
caseArrow

{
code = "="
}
]

project.layout = StandardConvention
runner.dialect = scala212source3
27 changes: 19 additions & 8 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.4"
lazy val scalaTest = "org.scalatest" %% "scalatest-flatspec" % "3.2.19"

ThisBuild / organization := "com.eed3si9n"
ThisBuild / scalaVersion := "2.12.8"
Expand All @@ -11,14 +11,24 @@ lazy val root = (project in file("."))
.settings(
name := "sbt-nocomma",
libraryDependencies ++= Vector(scalaTest % Test),
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value,
scriptedLaunchOpts := { scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
libraryDependencies ++= {
scalaBinaryVersion.value match {
case "3" =>
Nil
case _ =>
Seq("org.scala-lang" % "scala-compiler" % scalaVersion.value)
}
},
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
},
scriptedBufferLog := false,
crossScalaVersions += "3.3.4",
(pluginCrossBuild / sbtVersion) := {
scalaBinaryVersion.value match {
case "2.12" => "1.2.8"
case _ => "2.0.0-M2"
}
},
)
Expand All @@ -39,7 +49,9 @@ ThisBuild / developers := List(
)
ThisBuild / description := "sbt plugin to reduce commas from your build.sbt"
ThisBuild / homepage := Some(url("https://github.com/sbt/sbt-nocomma"))
ThisBuild / licenses := Seq("Apache-2.0" -> url("https://github.com/sbt/sbt-nocomma/blob/master/LICENSE"))
ThisBuild / licenses := Seq(
"Apache-2.0" -> url("https://github.com/sbt/sbt-nocomma/blob/master/LICENSE")
)
ThisBuild / pomIncludeRepository := { _ => false }
ThisBuild / publishTo := {
val nexus = "https://oss.sonatype.org/"
Expand All @@ -58,8 +70,7 @@ def pomConsistency2021DraftSettings: Seq[Setting[_]] = Seq(
pomConsistency2021Draft := Set("true", "1")(sys.env.get("POM_CONSISTENCY").getOrElse("false")),
moduleName := {
if (pomConsistency2021Draft.value)
sbtPluginModuleName2021Draft(moduleName.value,
(pluginCrossBuild / sbtBinaryVersion).value)
sbtPluginModuleName2021Draft(moduleName.value, (pluginCrossBuild / sbtBinaryVersion).value)
else moduleName.value
},
projectID := {
Expand All @@ -73,4 +84,4 @@ def sbtPluginModuleName2021Draft(n: String, sbtV: String): String =

def sbtPluginExtra2021Draft(m: ModuleID): ModuleID =
m.withExtraAttributes(Map.empty)
.withCrossVersion(CrossVersion.binary)
.withCrossVersion(CrossVersion.binary)
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.3
sbt.version=1.10.2
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ object NoComma {
Select(reify(Vector).tree, TermName("apply")),
items))
}
*/
*/
}
File renamed without changes.
36 changes: 36 additions & 0 deletions src/main/scala-3/NoComma.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package sbtnocomma

import sbt.*
import scala.quoted.Expr
import scala.quoted.Quotes
import scala.quoted.Varargs

object NoComma {
inline def nocomma(inline a: SettingsDefinition): Vector[Setting[?]] =
${ nocommaImpl('a) }

def nocommaImpl(a: Expr[SettingsDefinition])(using q: Quotes): Expr[Vector[Setting[?]]] = {
import q.reflect.*
a.asTerm match {
case Inlined(_, _, t: Block) =>
val values = (t.statements :+ t.expr).map {
case t: Term =>
t.asExpr match {
case '{ $x: Seq[Setting[?]] } =>
'{ Def.SettingList($x) }
case '{ $x: Setting[?] } =>
'{ Def.SettingList($x :: Nil) }
case '{ $x: SettingsDefinition } =>
x
case _ =>
report.errorAndAbort("unexpected")
}
case _ =>
report.errorAndAbort("unexpected")
}
'{ Vector[SettingsDefinition](${ Varargs(values) }*).flatMap(_.settings) }
case other =>
report.errorAndAbort("unexpected")
}
}
}
11 changes: 11 additions & 0 deletions src/main/scala-3/NoCommaPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package sbtnocomma

import sbt.*

object NoCommaPlugin extends AutoPlugin {
override def trigger = allRequirements
object autoImport {
inline def nocomma(inline a: SettingsDefinition): Vector[Setting[?]] =
${ NoComma.nocommaImpl('a) }
}
}
10 changes: 5 additions & 5 deletions src/test/scala/NoCommaTest.scala
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import org.scalatest._
import org.scalatest.flatspec._

import sbtnocomma.NoComma._
import sbt._, Keys._

class NoCommaSpec extends FlatSpec with Matchers {
class NoCommaSpec extends AnyFlatSpec {
"nocomma" should "expand to a Vector" in {
val seq = Seq(
scalacOptions += "-deprecation"
)
val xs = nocomma {
seq
name := "something"
organization in ThisBuild := "com.example"
ThisBuild / organization := "com.example"
}
val ys = Vector[SettingsDefinition](
seq,
name := "something",
organization in ThisBuild := "com.example",
ThisBuild / organization := "com.example",
)
assert((xs map { _.key }) === (ys flatMap { _.settings.map(_.key) }))
}
Expand All @@ -42,5 +42,5 @@ class NoCommaSpec extends FlatSpec with Matchers {
}
def f1 = 1
*/
*/
}

0 comments on commit fd37a52

Please sign in to comment.