Skip to content

Commit 83688b3

Browse files
committed
Add Scalafmt, Scalafix and other small improvements
1 parent 6303234 commit 83688b3

File tree

13 files changed

+150
-103
lines changed

13 files changed

+150
-103
lines changed

Diff for: .github/workflows/ci.yml

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ jobs:
2323
with:
2424
java-version: "[email protected]"
2525
- uses: coursier/cache-action@v5
26+
- name: Formatting
27+
run: sbt lint
2628
- name: Unit tests
2729
run: sbt "++${{ matrix.scalaversion }}" "${{ env.PROJECT_NAME }}/test"
2830
- name: Test generate documentation

Diff for: .scalafix.conf

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
rules = [
2+
ExplicitResultTypes
3+
LeakingImplicitClassVal
4+
NoAutoTupling
5+
NoValInForComprehension
6+
OrganizeImports
7+
ProcedureSyntax
8+
RemoveUnused
9+
]
10+
OrganizeImports {
11+
# Allign with IntelliJ IDEA so that they don't fight each other
12+
groupedImports = Merge
13+
}
14+
RemoveUnused {
15+
imports = false // handled by OrganizeImports
16+
}

Diff for: .scalafmt.conf

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version = "2.7.5"
2+
preset=Scala.js
3+
maxColumn = 100
4+
newlines.alwaysBeforeMultilineDef = false
5+
rewrite.rules = [AvoidInfix, PreferCurlyFors]
6+
docstrings.style = AsteriskSpace
7+
danglingParentheses.ctrlSite = false

Diff for: build.sbt

+72-53
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,63 @@
1-
// shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released
2-
import com.typesafe.tools.mima.core._
3-
import sbtcrossproject.{crossProject, CrossType}
1+
// shadow sbt-scalajs' crossProject until Scala.js 1.0.0 is released
2+
import sbtcrossproject.crossProject
43

54
val previousVersion = "1.1.1"
65

7-
inThisBuild(Def.settings(
8-
crossScalaVersions := Seq("2.12.13", "2.11.12", "2.13.4"),
9-
scalaVersion := crossScalaVersions.value.head,
10-
version := "1.1.2-SNAPSHOT",
11-
organization := "org.portable-scala",
12-
13-
scalacOptions ++= Seq(
14-
"-deprecation",
15-
"-feature",
16-
"-encoding",
17-
"utf-8",
18-
"-Xfatal-warnings",
19-
),
20-
21-
homepage := Some(url("https://github.com/portable-scala/portable-scala-reflect")),
22-
licenses += ("BSD New",
23-
url("https://github.com/portable-scala/portable-scala-reflect/blob/master/LICENSE")),
24-
scmInfo := Some(ScmInfo(
25-
url("https://github.com/portable-scala/portable-scala-reflect"),
26-
"scm:git:[email protected]:portable-scala/portable-scala-reflect.git",
27-
Some("scm:git:[email protected]:portable-scala/portable-scala-reflect.git"))),
28-
))
6+
inThisBuild(
7+
Def.settings(
8+
crossScalaVersions := Seq("2.13.4", "2.12.13", "2.11.12"),
9+
scalaVersion := crossScalaVersions.value.head,
10+
version := "1.1.2-SNAPSHOT",
11+
organization := "org.portable-scala",
12+
scalacOptions ++= Seq(
13+
"-deprecation",
14+
"-feature",
15+
"-encoding",
16+
"utf-8",
17+
"-Ywarn-unused"
18+
) ++ {
19+
if (sys.env.contains("CI")) {
20+
List("-Xfatal-warnings")
21+
} else {
22+
List() // to enable Scalafix locally
23+
}
24+
},
25+
semanticdbEnabled := true,
26+
semanticdbOptions += "-P:semanticdb:synthetics:on",
27+
semanticdbVersion := scalafixSemanticdb.revision,
28+
ThisBuild / scalafixScalaBinaryVersion := CrossVersion
29+
.binaryScalaVersion(scalaVersion.value),
30+
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.5.0",
31+
libraryDependencies ++= List(
32+
("com.github.ghik" % "silencer-lib" % "1.7.3" % Provided).cross(CrossVersion.full),
33+
compilerPlugin(
34+
("com.github.ghik" % "silencer-plugin" % "1.7.3").cross(CrossVersion.full)
35+
)
36+
),
37+
homepage := Some(url("https://github.com/portable-scala/portable-scala-reflect")),
38+
licenses += ("BSD New",
39+
url("https://github.com/portable-scala/portable-scala-reflect/blob/master/LICENSE")),
40+
scmInfo := Some(ScmInfo(url("https://github.com/portable-scala/portable-scala-reflect"),
41+
"scm:git:[email protected]:portable-scala/portable-scala-reflect.git",
42+
Some("scm:git:[email protected]:portable-scala/portable-scala-reflect.git")))
43+
))
2944

3045
lazy val `portable-scala-reflect` = crossProject(JSPlatform, JVMPlatform, NativePlatform)
3146
.in(file("."))
3247
.settings(
33-
scalacOptions in (Compile, doc) -= "-Xfatal-warnings",
34-
35-
mimaPreviousArtifacts +=
36-
organization.value %%% moduleName.value % previousVersion,
37-
38-
publishMavenStyle := true,
39-
publishTo := {
40-
val nexus = "https://oss.sonatype.org/"
41-
if (isSnapshot.value)
42-
Some("snapshots" at nexus + "content/repositories/snapshots")
43-
else
44-
Some("releases" at nexus + "service/local/staging/deploy/maven2")
45-
},
46-
pomExtra := (
47-
<developers>
48+
scalacOptions in (Compile, doc) -= "-Xfatal-warnings",
49+
mimaPreviousArtifacts +=
50+
organization.value %%% moduleName.value % previousVersion,
51+
publishMavenStyle := true,
52+
publishTo := {
53+
val nexus = "https://oss.sonatype.org/"
54+
if (isSnapshot.value)
55+
Some("snapshots".at(nexus + "content/repositories/snapshots"))
56+
else
57+
Some("releases".at(nexus + "service/local/staging/deploy/maven2"))
58+
},
59+
pomExtra := (
60+
<developers>
4861
<developer>
4962
<id>sjrd</id>
5063
<name>Sébastien Doeraene</name>
@@ -61,22 +74,28 @@ lazy val `portable-scala-reflect` = crossProject(JSPlatform, JVMPlatform, Native
6174
<url>https://github.com/densh/</url>
6275
</developer>
6376
</developers>
64-
),
65-
pomIncludeRepository := { _ => false },
77+
),
78+
pomIncludeRepository := { _ => false }
6679
)
6780
.jvmSettings(
68-
// Macros
69-
libraryDependencies += scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided,
70-
71-
// Speed up compilation a bit. Our .java files do not need to see the .scala files.
72-
compileOrder := CompileOrder.JavaThenScala,
73-
74-
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test",
81+
// Macros
82+
libraryDependencies += scalaOrganization.value % "scala-reflect" % scalaVersion.value % Provided,
83+
// Speed up compilation a bit. Our .java files do not need to see the .scala files.
84+
compileOrder := CompileOrder.JavaThenScala,
85+
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
7586
)
7687
.jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
7788
.nativeSettings(
78-
libraryDependencies +=
79-
"org.scala-native" %%% "junit-runtime" % "0.4.0" % "test",
80-
addCompilerPlugin(
81-
"org.scala-native" % "junit-plugin" % "0.4.0" cross CrossVersion.full),
89+
libraryDependencies +=
90+
"org.scala-native" %%% "junit-runtime" % "0.4.0" % "test",
91+
addCompilerPlugin(("org.scala-native" % "junit-plugin" % "0.4.0").cross(CrossVersion.full))
8292
)
93+
94+
addCommandAlias(
95+
"fix",
96+
"; all compile:scalafix test:scalafix; all scalafmtSbt scalafmtAll"
97+
)
98+
addCommandAlias(
99+
"lint",
100+
"; scalafmtSbtCheck; scalafmtCheckAll; compile:scalafix --check; test:scalafix --check"
101+
)

Diff for: js/src/main/scala/org/portablescala/reflect/Reflect.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.portablescala.reflect
22

3+
import com.github.ghik.silencer.silent
4+
35
import scala.scalajs.reflect.{Reflect => SJSReflect}
46

57
object Reflect {
8+
69
/** Reflectively looks up a loadable module class.
710
*
811
* A module class is the technical term referring to the class of a Scala
@@ -34,10 +37,10 @@ object Reflect {
3437
* Fully-qualified name of the module class, including its trailing `$`
3538
*
3639
* @param loader
37-
* Ignored
40+
* Ignored, used in the JVM variant and we need to keep the API
3841
*/
3942
def lookupLoadableModuleClass(fqcn: String,
40-
loader: ClassLoader): Option[LoadableModuleClass] = {
43+
@silent("never used") loader: ClassLoader): Option[LoadableModuleClass] = {
4144
lookupLoadableModuleClass(fqcn)
4245
}
4346

@@ -72,10 +75,10 @@ object Reflect {
7275
* Fully-qualified name of the class
7376
*
7477
* @param loader
75-
* Ignored
78+
* Ignored, used in the JVM variant and we need to keep the API
7679
*/
7780
def lookupInstantiatableClass(fqcn: String,
78-
loader: ClassLoader): Option[InstantiatableClass] = {
81+
@silent("never used") loader: ClassLoader): Option[InstantiatableClass] = {
7982
lookupInstantiatableClass(fqcn)
8083
}
8184
}

Diff for: jvm/src/main/scala/org/portablescala/reflect/InstantiatableClass.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import java.lang.reflect.InvocationTargetException
88
* The `java.lang.Class[_]` representing the class.
99
*/
1010
final class InstantiatableClass private[reflect] (val runtimeClass: Class[_]) {
11+
1112
/** A list of the public constructors declared in this class. */
1213
val declaredConstructors: List[InvokableConstructor] =
1314
runtimeClass.getConstructors().map(new InvokableConstructor(_)).toList
@@ -42,8 +43,7 @@ final class InstantiatableClass private[reflect] (val runtimeClass: Class[_]) {
4243
*/
4344
def getConstructor(parameterTypes: Class[_]*): Option[InvokableConstructor] = {
4445
try {
45-
Some(new InvokableConstructor(
46-
runtimeClass.getConstructor(parameterTypes: _*)))
46+
Some(new InvokableConstructor(runtimeClass.getConstructor(parameterTypes: _*)))
4747
} catch {
4848
case _: NoSuchMethodException => None
4949
}

Diff for: jvm/src/main/scala/org/portablescala/reflect/InvokableConstructor.scala

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java.lang.reflect.Constructor
44

55
/** A description of a constructor that can reflectively invoked. */
66
final class InvokableConstructor private[reflect] (ctor: Constructor[_]) {
7+
78
/** The `Class[_]` objects representing the formal parameters of this
89
* constructor.
910
*/

Diff for: jvm/src/main/scala/org/portablescala/reflect/LoadableModuleClass.scala

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package org.portablescala.reflect
66
* The `java.lang.Class[_]` representing the module class.
77
*/
88
final class LoadableModuleClass private[reflect] (val runtimeClass: Class[_]) {
9+
910
/** Loads the module instance and returns it.
1011
*
1112
* If the underlying constructor throws an exception `e`, then `loadModule`

Diff for: jvm/src/main/scala/org/portablescala/reflect/Reflect.scala

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package org.portablescala.reflect
22

3-
import scala.language.experimental.macros
4-
import scala.collection.mutable
5-
import java.lang.reflect._
63
import org.portablescala.reflect.annotation._
74
import org.portablescala.reflect.internal.Macros
85

6+
import java.lang.reflect._
7+
import scala.collection.mutable
8+
import scala.language.experimental.macros
9+
910
object Reflect {
1011

1112
/** Reflectively looks up a loadable module class using the current class
@@ -52,8 +53,7 @@ object Reflect {
5253
* @param loader
5354
* Class loader to use to load the module class
5455
*/
55-
def lookupLoadableModuleClass(fqcn: String,
56-
loader: ClassLoader): Option[LoadableModuleClass] = {
56+
def lookupLoadableModuleClass(fqcn: String, loader: ClassLoader): Option[LoadableModuleClass] = {
5757
load(fqcn, loader).filter(isModuleClass).map(new LoadableModuleClass(_))
5858
}
5959

@@ -101,8 +101,7 @@ object Reflect {
101101
* @param loader
102102
* Class loader to use to load the class
103103
*/
104-
def lookupInstantiatableClass(fqcn: String,
105-
loader: ClassLoader): Option[InstantiatableClass] = {
104+
def lookupInstantiatableClass(fqcn: String, loader: ClassLoader): Option[InstantiatableClass] = {
106105
load(fqcn, loader).filter(isInstantiatableClass).map(new InstantiatableClass(_))
107106
}
108107

Diff for: jvm/src/main/scala/org/portablescala/reflect/internal/Macros.scala

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.portablescala.reflect.internal
22

3+
import com.github.ghik.silencer.silent
34
import org.portablescala.reflect._
45

56
/* Macro definitions are enclosed in a dedicated `Macros` object,
@@ -9,9 +10,11 @@ import org.portablescala.reflect._
910
* https://github.com/xeno-by/sbt-example-paradise210/issues/1#issuecomment-20996354
1011
*/
1112
object Macros {
13+
1214
/** Magic to get cross-compiling access to `blackbox.Context` with a fallback
1315
* on `macros.Context`, without deprecation warning in any Scala version.
1416
*/
17+
@silent("Unused import")
1518
private object MacroCompat {
1619
object Scope1 {
1720
object blackbox
@@ -41,8 +44,7 @@ object Macros {
4144
}
4245
}
4346

44-
def lookupLoadableModuleClass(
45-
c: BlackboxContext { type PrefixType = Reflect.type })(
47+
def lookupLoadableModuleClass(c: BlackboxContext { type PrefixType = Reflect.type })(
4648
fqcn: c.Expr[String]): c.Expr[Option[LoadableModuleClass]] = {
4749
import c.universe._
4850
val loaderExpr = currentClassLoaderExpr(c)
@@ -51,8 +53,7 @@ object Macros {
5153
}
5254
}
5355

54-
def lookupInstantiatableClass(
55-
c: BlackboxContext { type PrefixType = Reflect.type })(
56+
def lookupInstantiatableClass(c: BlackboxContext { type PrefixType = Reflect.type })(
5657
fqcn: c.Expr[String]): c.Expr[Option[InstantiatableClass]] = {
5758
import c.universe._
5859
val loaderExpr = currentClassLoaderExpr(c)

Diff for: native/src/main/scala/org/portablescala/reflect/Reflect.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package org.portablescala.reflect
22

3+
import com.github.ghik.silencer.silent
4+
35
import scala.scalanative.reflect.{Reflect => ScalaNativeReflect}
46

57
object Reflect {
8+
69
/** Reflectively looks up a loadable module class.
710
*
811
* A module class is the technical term referring to the class of a Scala
@@ -34,10 +37,10 @@ object Reflect {
3437
* Fully-qualified name of the module class, including its trailing `$`
3538
*
3639
* @param loader
37-
* Ignored
40+
* Ignored, used in the JVM variant and we need to keep the API
3841
*/
3942
def lookupLoadableModuleClass(fqcn: String,
40-
loader: ClassLoader): Option[LoadableModuleClass] = {
43+
@silent("never used") loader: ClassLoader): Option[LoadableModuleClass] = {
4144
lookupLoadableModuleClass(fqcn)
4245
}
4346

@@ -72,10 +75,10 @@ object Reflect {
7275
* Fully-qualified name of the class
7376
*
7477
* @param loader
75-
* Ignored
78+
* Ignored, used in the JVM variant and we need to keep the API
7679
*/
7780
def lookupInstantiatableClass(fqcn: String,
78-
loader: ClassLoader): Option[InstantiatableClass] = {
81+
@silent("never used") loader: ClassLoader): Option[InstantiatableClass] = {
7982
lookupInstantiatableClass(fqcn)
8083
}
8184
}

Diff for: project/plugins.sbt

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ val scalaJSVersion =
22
Option(System.getenv("SCALAJS_VERSION")).filter(_ != "").getOrElse("1.0.0")
33

44
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
5-
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
5+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.0.0")
66

77
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")
88
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.0.0")
99

1010
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.8.1")
11+
12+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
13+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.26")

0 commit comments

Comments
 (0)