Skip to content

Commit d120998

Browse files
committed
run scalafmt, fail build if there is a violation
1 parent 6822f09 commit d120998

File tree

7 files changed

+113
-85
lines changed

7 files changed

+113
-85
lines changed

binary-compat/test/src/test/scala/BinaryCompaTest.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@ class BinaryCompaTest {
2727
allProblems.iterator
2828
.map(_.description("new"))
2929
// code improvement: it would be more standard to use a ProblemFilter here
30-
.filterNot(_ == "static method id(scala.collection.Iterable,scala.collection.generic.CanBuildFrom)scala.collection.Iterable in class org.example.Lib has a different signature in new version, where it is <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<Lscala/runtime/Nothing$;TA;TC;>;)TC; rather than <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<TC;TA;TC;>;)TC;")
31-
.filterNot(_ == "method id(scala.collection.Iterable,scala.collection.generic.CanBuildFrom)scala.collection.Iterable in object org.example.Lib has a different signature in new version, where it is <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<Lscala/runtime/Nothing$;TA;TC;>;)TC; rather than <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<TC;TA;TC;>;)TC;")
30+
.filterNot(
31+
_ == "static method id(scala.collection.Iterable,scala.collection.generic.CanBuildFrom)scala.collection.Iterable in class org.example.Lib has a different signature in new version, where it is <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<Lscala/runtime/Nothing$;TA;TC;>;)TC; rather than <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<TC;TA;TC;>;)TC;")
32+
.filterNot(
33+
_ == "method id(scala.collection.Iterable,scala.collection.generic.CanBuildFrom)scala.collection.Iterable in object org.example.Lib has a different signature in new version, where it is <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<Lscala/runtime/Nothing$;TA;TC;>;)TC; rather than <A:Ljava/lang/Object;C::Lscala/collection/Iterable<Ljava/lang/Object;>;>(TC;Lscala/collection/generic/CanBuildFrom<TC;TA;TC;>;)TC;")
3234
.toList
3335
val msg =
3436
unexpectedDescriptions.mkString(
35-
s"The following ${unexpectedDescriptions.size} problems were reported but not expected:\n - ", "\n - ", "\n")
37+
s"The following ${unexpectedDescriptions.size} problems were reported but not expected:\n - ",
38+
"\n - ",
39+
"\n")
3640
Assert.assertEquals(msg, Nil, unexpectedDescriptions)
3741
}
3842
}

build.sbt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ lazy val dontPublish = Seq(
282282
)
283283

284284
val travisScalaVersion = sys.env.get("TRAVIS_SCALA_VERSION").flatMap(Version.parse)
285-
val isTravisTag = sys.env.get("TRAVIS_TAG").map(_.nonEmpty).getOrElse(false)
286-
val isScalaJs = sys.env.get("SCALAJS_VERSION").map(_.nonEmpty).getOrElse(false)
287-
val isScalaNative = sys.env.get("SCALANATIVE_VERSION").map(_.nonEmpty).getOrElse(false)
285+
val isTravisTag = sys.env.get("TRAVIS_TAG").exists(_.nonEmpty)
286+
val isScalaJs = sys.env.get("SCALAJS_VERSION").exists(_.nonEmpty)
287+
val isScalaNative = sys.env.get("SCALANATIVE_VERSION").exists(_.nonEmpty)
288288
val isScalafix = sys.env.get("TEST_SCALAFIX").nonEmpty
289289
val isScalafmt = sys.env.get("TEST_SCALAFMT").nonEmpty
290290
val isBinaryCompat = sys.env.get("TEST_BINARY_COMPAT").nonEmpty
@@ -294,8 +294,8 @@ val jdkVersion = sys.env.get("ADOPTOPENJDK").map(_.toInt)
294294
inThisBuild(
295295
Seq(
296296
commands += Command.command("scalafmt-test") { state =>
297-
Seq("admin/scalafmt.sh", "--test") ! state.globalLogging.full
298-
state
297+
val exitCode = Seq("admin/scalafmt.sh", "--test") ! state.globalLogging.full
298+
if (exitCode == 0) state else state.fail
299299
},
300300
commands += Command.command("scalafmt") { state =>
301301
Seq("admin/scalafmt.sh") ! state.globalLogging.full
@@ -315,7 +315,7 @@ inThisBuild(
315315
"TEST_SCALAFMT",
316316
"TEST_BINARY_COMPAT"
317317
).foreach(k =>
318-
println(k.padTo(20, " ").mkString("") + " -> " + sys.env.get(k).getOrElse("None")))
318+
println(k.padTo(20, " ").mkString("") + " -> " + sys.env.getOrElse(k, "None")))
319319

320320
val platformSuffix = if (isScalaJs) "JS" else if (isScalaNative) "Native" else ""
321321

compat/src/main/scala-2.11/scala/collection/compat/package.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ package object compat extends compat.PackageShared {
2727
// CanBuildFrom instances for `IterableView[(K, V), Map[K, V]]` that preserve
2828
// the strict type of the view to be `Map` instead of `Iterable`
2929
// Instances produced by this method are used to chain `filterKeys` after `mapValues`
30-
implicit def canBuildFromIterableViewMapLike[K, V, L, W, CC[X, Y] <: Map[X, Y]]: CanBuildFrom[IterableView[(K, V), CC[K, V]], (L, W), IterableView[(L, W), CC[L, W]]] =
30+
implicit def canBuildFromIterableViewMapLike[K, V, L, W, CC[X, Y] <: Map[X, Y]]
31+
: CanBuildFrom[IterableView[(K, V), CC[K, V]], (L, W), IterableView[(L, W), CC[L, W]]] =
3132
new CanBuildFrom[IterableView[(K, V), CC[K, V]], (L, W), IterableView[(L, W), CC[L, W]]] {
3233
// `CanBuildFrom` parameters are used as type constraints, they are not used
3334
// at run-time, hence the dummy builder implementations

compat/src/main/scala-2.11_2.12/scala/collection/compat/CompatImpl.scala

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,16 @@ import scala.collection.{immutable => i, mutable => m}
1919
/* builder optimized for a single ++= call, which returns identity on result if possible
2020
* and defers to the underlying builder if not.
2121
*/
22-
private final class IdentityPreservingBuilder[A, CC[X] <: TraversableOnce[X]](that: m.Builder[A, CC[A]])(implicit ct: ClassTag[CC[A]])
22+
private final class IdentityPreservingBuilder[A, CC[X] <: TraversableOnce[X]](
23+
that: m.Builder[A, CC[A]])(implicit ct: ClassTag[CC[A]])
2324
extends m.Builder[A, CC[A]] {
2425

2526
//invariant: ruined => (collection == null)
2627
var collection: CC[A] = null.asInstanceOf[CC[A]]
27-
var ruined = false
28+
var ruined = false
2829

2930
private[this] def ruin(): Unit = {
30-
if(collection != null) that ++= collection
31+
if (collection != null) that ++= collection
3132
collection = null.asInstanceOf[CC[A]]
3233
ruined = true
3334
}
@@ -57,14 +58,15 @@ private final class IdentityPreservingBuilder[A, CC[X] <: TraversableOnce[X]](th
5758
ruined = false
5859
}
5960

60-
def result(): CC[A] = if(collection == null) that.result() else collection
61+
def result(): CC[A] = if (collection == null) that.result() else collection
6162
}
6263

6364
private[compat] object CompatImpl {
64-
def simpleCBF[A, C](f: => m.Builder[A, C]): CanBuildFrom[Any, A, C] = new CanBuildFrom[Any, A, C] {
65-
def apply(from: Any): m.Builder[A, C] = apply()
66-
def apply(): m.Builder[A, C] = f
67-
}
65+
def simpleCBF[A, C](f: => m.Builder[A, C]): CanBuildFrom[Any, A, C] =
66+
new CanBuildFrom[Any, A, C] {
67+
def apply(from: Any): m.Builder[A, C] = apply()
68+
def apply(): m.Builder[A, C] = f
69+
}
6870

6971
type ImmutableBitSetCC[X] = ({ type L[_] = i.BitSet })#L[X]
7072
type MutableBitSetCC[X] = ({ type L[_] = m.BitSet })#L[X]

compat/src/main/scala-2.11_2.12/scala/collection/compat/immutable/LazyList.scala

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ import java.io.{ObjectInputStream, ObjectOutputStream}
1616

1717
import scala.annotation.tailrec
1818
import scala.annotation.unchecked.{uncheckedVariance => uV}
19-
import scala.collection.{AbstractIterator, AbstractSeq, GenIterable, GenSeq, GenTraversableOnce, LinearSeqOptimized, mutable}
20-
import scala.collection.generic.{CanBuildFrom, FilterMonadic, GenericCompanion, GenericTraversableTemplate, SeqFactory}
19+
import scala.collection.{
20+
AbstractIterator,
21+
AbstractSeq,
22+
GenIterable,
23+
GenSeq,
24+
GenTraversableOnce,
25+
LinearSeqOptimized,
26+
mutable
27+
}
28+
import scala.collection.generic.{
29+
CanBuildFrom,
30+
FilterMonadic,
31+
GenericCompanion,
32+
GenericTraversableTemplate,
33+
SeqFactory
34+
}
2135
import scala.collection.immutable.{LinearSeq, NumericRange}
2236
import scala.collection.mutable.{ArrayBuffer, Builder, StringBuilder}
2337
import scala.language.implicitConversions
@@ -513,7 +527,9 @@ final class LazyList[+A] private (private[this] var lazyState: () => LazyList.St
513527
*
514528
* $preservesLaziness
515529
*/
516-
def tapEach[U](f: A => U): LazyList[A] = mapToLL { a => f(a); a }
530+
def tapEach[U](f: A => U): LazyList[A] = mapToLL { a =>
531+
f(a); a
532+
}
517533

518534
private def mapImpl[B](f: A => B): LazyList[B] =
519535
newLL {
@@ -754,7 +770,6 @@ final class LazyList[+A] private (private[this] var lazyState: () => LazyList.St
754770
occ
755771
}
756772

757-
758773
/** @inheritdoc
759774
*
760775
* $preservesLaziness
@@ -765,7 +780,7 @@ final class LazyList[+A] private (private[this] var lazyState: () => LazyList.St
765780
val occ = occCounts0(that.seq)
766781
LazyList.from {
767782
iterator.filter { x =>
768-
val ox = occ(x) // Avoid multiple map lookups
783+
val ox = occ(x) // Avoid multiple map lookups
769784
if (ox == 0) true
770785
else {
771786
occ(x) = ox - 1
@@ -785,7 +800,7 @@ final class LazyList[+A] private (private[this] var lazyState: () => LazyList.St
785800
val occ = occCounts0(that.seq)
786801
LazyList.from {
787802
iterator.filter { x =>
788-
val ox = occ(x) // Avoid multiple map lookups
803+
val ox = occ(x) // Avoid multiple map lookups
789804
if (ox > 0) {
790805
occ(x) = ox - 1
791806
true
@@ -1034,32 +1049,33 @@ final class LazyList[+A] private (private[this] var lazyState: () => LazyList.St
10341049

10351050
def distinctBy[B](f: A => B): LazyList[A] =
10361051
if (knownIsEmpty) LazyList.empty
1037-
else LazyList.from {
1038-
val outer = iterator
1039-
new AbstractIterator[A] {
1040-
private[this] val traversedValues = mutable.HashSet.empty[B]
1041-
private[this] var nextElementDefined: Boolean = false
1042-
private[this] var nextElement: A = _
1043-
1044-
def hasNext: Boolean = nextElementDefined || (outer.hasNext && {
1045-
val a = outer.next()
1046-
if (traversedValues.add(f(a))) {
1047-
nextElement = a
1048-
nextElementDefined = true
1049-
true
1050-
}
1051-
else hasNext
1052-
})
1053-
1054-
def next(): A =
1055-
if (hasNext) {
1056-
nextElementDefined = false
1057-
nextElement
1058-
} else {
1059-
Iterator.empty.next()
1060-
}
1052+
else
1053+
LazyList.from {
1054+
val outer = iterator
1055+
new AbstractIterator[A] {
1056+
private[this] val traversedValues = mutable.HashSet.empty[B]
1057+
private[this] var nextElementDefined: Boolean = false
1058+
private[this] var nextElement: A = _
1059+
1060+
def hasNext: Boolean =
1061+
nextElementDefined || (outer.hasNext && {
1062+
val a = outer.next()
1063+
if (traversedValues.add(f(a))) {
1064+
nextElement = a
1065+
nextElementDefined = true
1066+
true
1067+
} else hasNext
1068+
})
1069+
1070+
def next(): A =
1071+
if (hasNext) {
1072+
nextElementDefined = false
1073+
nextElement
1074+
} else {
1075+
Iterator.empty.next()
1076+
}
1077+
}
10611078
}
1062-
}
10631079

10641080
override def to[Col[_]](implicit cbf: CanBuildFrom[Nothing, A, Col[A @uV]]): Col[A @uV] =
10651081
if (cbf().isInstanceOf[LazyList.LazyBuilder[_]]) asThat(this)
@@ -1503,9 +1519,9 @@ object LazyList extends SeqFactory[LazyList] {
15031519
override def iterate[A](start: A, len: Int)(f: A => A): LazyList[A] =
15041520
iterate(start)(f).take(len)
15051521

1506-
override def range[A : Integral](start: A, end: A): LazyList[A] =
1522+
override def range[A: Integral](start: A, end: A): LazyList[A] =
15071523
from(NumericRange(start, end, implicitly[Integral[A]].one))
15081524

1509-
override def range[A : Integral](start: A, end: A, step: A): LazyList[A] =
1525+
override def range[A: Integral](start: A, end: A, step: A): LazyList[A] =
15101526
from(NumericRange(start, end, step))
15111527
}

compat/src/test/scala/test/scala/collection/LazyListLazinessTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ class LazyListLazinessTest {
869869
}
870870
object CustomLong {
871871
import scala.language.implicitConversions
872-
def apply(value: Long): CustomLong = new CustomLong(value)
872+
def apply(value: Long): CustomLong = new CustomLong(value)
873873
implicit def long2CustomLong(long: Long): CustomLong = apply(long)
874874

875875
implicit val customIntegralIsIntegral: Integral[CustomLong] = new Integral[CustomLong] {

0 commit comments

Comments
 (0)