Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add in Scalafmt #262

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Introduce scalafmt
eaddef6e438031050dafbafbc0b5bc5d43f95b11
14 changes: 14 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ jobs:
- name: Check Binary Compatibility
run: ./mill -i --disable-ticker __.mimaReportBinaryIssues

check-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 17

- run: ./mill -i -k __.checkFormat

publish-sonatype:
if: github.repository == 'com-lihaoyi/scalatags' && contains(github.ref, 'refs/tags/')
needs: test
Expand Down
28 changes: 28 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version = "3.6.1"

project.git = true

align.preset = none
align.openParenCallSite = false
align.stripMargin = true

assumeStandardLibraryStripMargin = true

continuationIndent.callSite = 2
continuationIndent.defnSite = 4

docstrings.style = Asterisk
docstrings.oneline = keep
docstrings.wrap = no

maxColumn = 100

newlines.source = keep

runner.dialect = scala213

fileOverride {
"glob:**/scalatags/src-3/**" {
runner.dialect = scala3
}
}
10 changes: 5 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@

lazy val readme = scalatex.ScalatexReadme(
projectId = "readme",
wd = file(""),
url = "https://github.com/lihaoyi/scalatags/tree/master",
source = "Readme",
autoResources = Seq("Autocomplete.png", "ErrorHighlighting.png", "InlineDocs.png", "example-opt.js")
autoResources =
Seq("Autocomplete.png", "ErrorHighlighting.png", "InlineDocs.png", "example-opt.js")
).settings(
scalaVersion := "2.12.8",
(unmanagedSources in Compile) += baseDirectory.value/".."/"project"/"Constants.scala",
(unmanagedSources in Compile) += baseDirectory.value / ".." / "project" / "Constants.scala",
(resources in Compile) += (fullOptJS in (example, Compile)).value.data,
(resources in Compile) += (doc in (scalatagsJS, Compile)).value,
(run in Compile) := (run in Compile).dependsOn(Def.task{
(run in Compile) := (run in Compile).dependsOn(Def.task {
sbt.IO.copyDirectory(
(doc in (scalatagsJS, Compile)).value,
(target in Compile).value/"scalatex"/"api",
(target in Compile).value / "scalatex" / "api",
overwrite = true
)
}).evaluated
Expand Down
53 changes: 28 additions & 25 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import de.tobiasroeser.mill.vcs.version.VcsVersion
import $ivy.`com.github.lolgab::mill-mima::0.0.13`
import com.github.lolgab.mill.mima._
import mill.scalalib.api.Util.isScala3
import mill.scalalib.scalafmt._

val dottyVersions = sys.props.get("dottyVersion").toList

Expand All @@ -22,7 +23,6 @@ trait MimaCheck extends Mima {
trait ScalatagsPublishModule extends PublishModule with MimaCheck {
def artifactName = "scalatags"


def publishVersion = VcsVersion.vcsState().format()

def crossScalaVersion: String
Expand All @@ -42,27 +42,28 @@ trait ScalatagsPublishModule extends PublishModule with MimaCheck {
)
}

trait Common extends CrossScalaModule {
trait Common extends CrossScalaModule with ScalafmtModule {
def millSourcePath = super.millSourcePath / offset
def ivyDeps = Agg(
ivy"com.lihaoyi::sourcecode::0.3.0",
ivy"com.lihaoyi::geny::1.0.0",
ivy"com.lihaoyi::geny::1.0.0"
)
def compileIvyDeps = T { super.compileIvyDeps() ++
(
if (isScala3(crossScalaVersion)) Agg()
else Agg(
ivy"org.scala-lang:scala-reflect:${scalaVersion()}"
def compileIvyDeps = T {
super.compileIvyDeps() ++
(
if (isScala3(crossScalaVersion)) Agg()
else Agg(
ivy"org.scala-lang:scala-reflect:${scalaVersion()}"
)
)
)
}
def offset: os.RelPath = os.rel
def sources = T.sources(
super.sources()
.flatMap(source =>
Seq(
PathRef(source.path / os.up / source.path.last),
PathRef(source.path / os.up / os.up / source.path.last),
PathRef(source.path / os.up / os.up / source.path.last)
)
)
)
Expand All @@ -71,7 +72,7 @@ trait Common extends CrossScalaModule {
trait CommonTestModule extends ScalaModule with TestModule.Utest with BuildInfo {
def millSourcePath = super.millSourcePath / os.up
def crossScalaVersion: String
val scalaXmlVersion = if(crossScalaVersion.startsWith("2.11.")) "1.3.0" else "2.1.0"
val scalaXmlVersion = if (crossScalaVersion.startsWith("2.11.")) "1.3.0" else "2.1.0"
def ivyDeps = Agg(
ivy"com.lihaoyi::utest::0.8.1",
ivy"org.scala-lang.modules::scala-xml:$scalaXmlVersion"
Expand All @@ -82,7 +83,7 @@ trait CommonTestModule extends ScalaModule with TestModule.Utest with BuildInfo
.flatMap(source =>
Seq(
PathRef(source.path / os.up / "test" / source.path.last),
PathRef(source.path / os.up / os.up / "test" / source.path.last),
PathRef(source.path / os.up / os.up / "test" / source.path.last)
)
)
.distinct
Expand All @@ -93,46 +94,48 @@ trait CommonTestModule extends ScalaModule with TestModule.Utest with BuildInfo
)
}


object scalatags extends Module {
object jvm extends Cross[JvmScalatagsModule](scalaVersions:_*)
object jvm extends Cross[JvmScalatagsModule](scalaVersions: _*)
class JvmScalatagsModule(val crossScalaVersion: String)
extends Common with ScalaModule with ScalatagsPublishModule {
extends Common with ScalaModule with ScalatagsPublishModule {

object test extends Tests with CommonTestModule{
object test extends Tests with CommonTestModule {
def crossScalaVersion = JvmScalatagsModule.this.crossScalaVersion
}
}

object js extends Cross[JSScalatagsModule](scalaJSVersions:_*)
object js extends Cross[JSScalatagsModule](scalaJSVersions: _*)
class JSScalatagsModule(val crossScalaVersion: String, crossJSVersion: String)
extends Common with ScalaJSModule with ScalatagsPublishModule {
extends Common with ScalaJSModule with ScalatagsPublishModule {
def scalaJSVersion = crossJSVersion
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scala-js::scalajs-dom::2.3.0")
def offset = os.up
object test extends Tests with CommonTestModule{
object test extends Tests with CommonTestModule {
def offset = os.up
def crossScalaVersion = JSScalatagsModule.this.crossScalaVersion
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scala-js::scalajs-env-jsdom-nodejs:1.1.0").map(_.withDottyCompat(crossScalaVersion))
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scala-js::scalajs-env-jsdom-nodejs:1.1.0").map(
_.withDottyCompat(crossScalaVersion)
)
def jsEnvConfig = mill.scalajslib.api.JsEnvConfig.JsDom()
}
}

object native extends Cross[NativeScalatagsModule](scalaNativeVersions:_*)
object native extends Cross[NativeScalatagsModule](scalaNativeVersions: _*)
class NativeScalatagsModule(val crossScalaVersion: String, crossScalaNativeVersion: String)
extends Common with ScalaNativeModule with ScalatagsPublishModule {
extends Common with ScalaNativeModule with ScalatagsPublishModule {
def scalaNativeVersion = crossScalaNativeVersion
// No released Scala Native Scala 3 version yet
def mimaPreviousArtifacts = if(isScala3(crossScalaVersion)) Agg.empty[Dep] else super.mimaPreviousArtifacts()
def mimaPreviousArtifacts =
if (isScala3(crossScalaVersion)) Agg.empty[Dep] else super.mimaPreviousArtifacts()
def offset = os.up
object test extends Tests with CommonTestModule{
object test extends Tests with CommonTestModule {
def offset = os.up
def crossScalaVersion = NativeScalatagsModule.this.crossScalaVersion
}
}
}

object example extends ScalaJSModule{
object example extends ScalaJSModule {
val (scalaV, scalaJSV) = scalaJSVersions.head
def scalaVersion = scalaV
def scalaJSVersion = scalaJSV
Expand Down
82 changes: 55 additions & 27 deletions example/src/example/ScalaJSExample.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package example
import scala.scalajs.js.annotation.JSExportTopLevel
import org.scalajs.dom
class Example[Builder, Output <: FragT, FragT]
(val bundle: scalatags.generic.Bundle[Builder, Output, FragT]){
class Example[Builder, Output <: FragT, FragT](val bundle: scalatags.generic.Bundle[
Builder,
Output,
FragT
]) {
val htmlFrag = {
import bundle.all._
div(
Expand All @@ -18,20 +21,34 @@ class Example[Builder, Output <: FragT, FragT]
"text inside. You can have lots and lots of ",
"text"
),
b("bold"), " ",
i("italic"), " ",
s("strikethrough"), " ",
u("underlined"), " ",
em("emphasis"), " ",
strong("strong"), " ",
sub("sub"), " ",
sup("sup"), " ",
code("code"), " ",
a("a-link"), " ",
small("small"), " ",
cite("cite"), " ",
ins("ins"), " ",
del("del"), " ",
b("bold"),
" ",
i("italic"),
" ",
s("strikethrough"),
" ",
u("underlined"),
" ",
em("emphasis"),
" ",
strong("strong"),
" ",
sub("sub"),
" ",
sup("sup"),
" ",
code("code"),
" ",
a("a-link"),
" ",
small("small"),
" ",
cite("cite"),
" ",
ins("ins"),
" ",
del("del"),
" ",
hr,
ol(
li("Ordered List Item 1"),
Expand Down Expand Up @@ -89,7 +106,8 @@ class Example[Builder, Output <: FragT, FragT]
)
),
hr,
label("input"), input,
label("input"),
input,
br,
label("select"),
select(
Expand All @@ -113,14 +131,18 @@ class Example[Builder, Output <: FragT, FragT]
strokeWidth := "3"
),
line(
x1 := 175, y1 := 100,
x2 := 275, y2 := 0,
x1 := 175,
y1 := 100,
x2 := 275,
y2 := 0,
stroke := "rgb(255,0,0)",
strokeWidth := 10
),
rect(
x := 300, y := 10,
rx := 20, ry := 20,
x := 300,
y := 10,
rx := 20,
ry := 20,
width := 100,
height := 100,
fill := "rgb(0,0,255)",
Expand All @@ -130,15 +152,18 @@ class Example[Builder, Output <: FragT, FragT]
strokeOpacity := "0.5"
),
circle(
cx := 30, cy := 250,
cx := 30,
cy := 250,
r := 10,
stroke := "black",
strokeWidth := 3,
fill := "red"
),
ellipse(
cx := 150, cy := 250,
rx := 100, ry := 50,
cx := 150,
cy := 250,
rx := 100,
ry := 50,
fill := "yellow",
stroke := "purple",
strokeWidth := 4
Expand All @@ -153,7 +178,8 @@ class Example[Builder, Output <: FragT, FragT]
d := "M100 300 L25 500 L175 500 Z"
),
text(
x := 350, y := 250,
x := 350,
y := 250,
fill := "red",
transform := "rotate(30 20, 40)",
"I love SVG!"
Expand Down Expand Up @@ -181,8 +207,10 @@ class Example[Builder, Output <: FragT, FragT]
)
),
ellipse(
cx := 100, cy := 590,
rx := 85, ry := 55,
cx := 100,
cy := 590,
rx := 85,
ry := 55,
fill := "url(#grad1)"
)
)
Expand Down
2 changes: 1 addition & 1 deletion project/Constants.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package scalatags
object Constants{
object Constants {
val version = "0.9.4"
}
Loading