Skip to content

Commit

Permalink
Update Scalafmt
Browse files Browse the repository at this point in the history
  • Loading branch information
travisbrown committed Apr 24, 2020
1 parent a3fd7d7 commit d06893e
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 40 deletions.
5 changes: 3 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version=2.4.2
version=2.5.0-RC1
align.openParenCallSite = true
align.openParenDefnSite = true
maxColumn = 120
continuationIndent.defnSite = 2
assumeStandardLibraryStripMargin = true
danglingParentheses = true
rewrite.rules = [AvoidInfix, SortImports, RedundantBraces, RedundantParens, SortModifiers]
rewrite.rules = [AvoidInfix, SortImports, RedundantParens, SortModifiers]
docstrings = JavaDoc
newlines.alwaysBeforeMultilineDef = false
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object Canonicalization {
case i => F.pure(i)
}

def canonicalize[F[_]](parent: ImportContext, child: ImportContext)(
implicit F: Sync[F]
def canonicalize[F[_]](parent: ImportContext, child: ImportContext)(implicit
F: Sync[F]
): F[ImportContext] =
parent match {
case Remote(uri, headers) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ object ImportCache {

def backupCache =
for {
cacheO <- if (isWindows)
makeCacheFromEnvVar("LOCALAPPDATA", "")
else makeCacheFromEnvVar("HOME", ".cache")
cacheO <-
if (isWindows)
makeCacheFromEnvVar("LOCALAPPDATA", "")
else makeCacheFromEnvVar("HOME", ".cache")
cache <- cacheO.fold[F[ImportCache[F]]](F.as(warnCacheNotCreated, new NoopImportCache[F]))(F.pure)
} yield cache

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final private class ResolveImportsVisitor[F[_] <: AnyRef](
semanticCache: ImportCache[F],
semiSemanticCache: ImportCache[F],
parents: NonEmptyList[ImportContext]
)(
implicit Client: Client[F],
)(implicit
Client: Client[F],
F: Sync[F]
) extends LiftVisitor[F](F) {
def this(
Expand Down Expand Up @@ -211,11 +211,13 @@ private object ResolveImportsVisitor {

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F],
semiSemanticCache: ImportCache[F],
relativeTo: Path): ResolveImportsVisitor[F] =
relativeTo: Path
): ResolveImportsVisitor[F] =
//We add a placeholder filename "package.dhall" for the base directory as a Local import must have a filename
new ResolveImportsVisitor(semanticCache,
semiSemanticCache,
NonEmptyList.one(Local(relativeTo.resolve("package.dhall"))))
NonEmptyList.one(Local(relativeTo.resolve("package.dhall")))
)

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F], relativeTo: Path): ResolveImportsVisitor[F] =
apply[F](semanticCache, new ImportCache.NoopImportCache, relativeTo)
Expand All @@ -225,7 +227,8 @@ private object ResolveImportsVisitor {
def apply[F[_] <: AnyRef: Sync: Client]: F[ResolveImportsVisitor[F]] = apply[F](cwd)

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F],
semiSemanticCache: ImportCache[F]): ResolveImportsVisitor[F] =
semiSemanticCache: ImportCache[F]
): ResolveImportsVisitor[F] =
apply[F](semanticCache, semiSemanticCache, cwd)

def apply[F[_] <: AnyRef: Sync: Client](semanticCache: ImportCache[F]): ResolveImportsVisitor[F] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ class CanonicalizationSuite extends FunSuite {

test("Imports - quoted") {
assertEquals(canonicalize[IO](Local(Paths.get("/\"foo\"/\"bar.dhall\""))).unsafeRunSync,
Local(Paths.get("/foo/bar.dhall")))
Local(Paths.get("/foo/bar.dhall"))
)
}

test("Paths - Trailing .") {
assertEquals(canonicalize[IO](Local(Paths.get("/foo/./bar.dhall"))).unsafeRunSync,
Local(Paths.get("/foo/bar.dhall")))
Local(Paths.get("/foo/bar.dhall"))
)
}

test("Paths - Trailing ..") {
assertEquals(canonicalize[IO](Local(Paths.get("/foo/bar/../baz.dhall"))).unsafeRunSync,
Local(Paths.get("/foo/baz.dhall")))
Local(Paths.get("/foo/baz.dhall"))
)
}

//TODO determine whether spec is correct on this
Expand Down Expand Up @@ -155,30 +158,37 @@ class CanonicalizationSuite extends FunSuite {

test("Chaining - local / remote") {
assertEquals(
canonicalize[IO](Local(Paths.get("/foo/bar.dhall")), Remote(new URI("http://foo.org/bar.dhall"), headers1)).unsafeRunSync,
canonicalize[IO](Local(Paths.get("/foo/bar.dhall")),
Remote(new URI("http://foo.org/bar.dhall"), headers1)
).unsafeRunSync,
Remote(new URI("http://foo.org/bar.dhall"), headers1)
)
}

test("Chaining - remote / remote absolute") {
assertEquals(
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1),
Remote(new URI("https://bar.com/bar/baz.dhall"), headers2)).unsafeRunSync,
Remote(new URI("https://bar.com/bar/baz.dhall"), headers2)
).unsafeRunSync,
Remote((new URI("https://bar.com/bar/baz.dhall")), headers2)
)
}

test("Chaining - remote / local relative") {
assertEquals(
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1), Local(Paths.get("./baz.dhall"))).unsafeRunSync,
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1),
Local(Paths.get("./baz.dhall"))
).unsafeRunSync,
Remote(new URI("http://foo.org/baz.dhall"), headers1)
)
}

//This is actually prohibited by the sanity check but we don't worry about it here
test("Chaining - remote / local absolute") {
assertEquals(
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1), Local(Paths.get("/baz.dhall"))).unsafeRunSync,
canonicalize[IO](Remote(new URI("http://foo.org/bar.dhall"), headers1),
Local(Paths.get("/baz.dhall"))
).unsafeRunSync,
Local(Paths.get("/baz.dhall"))
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class CorsComplianceCheckSuite extends FunSuite {
test("Remote - different origin, allow *") {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "*"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "*"))
).unsafeRunSync()
}

test("Remote - different origin, allow parent authority") {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))
).unsafeRunSync()
}

test("Remote - different origin".fail) {
Expand All @@ -40,25 +42,29 @@ class CorsComplianceCheckSuite extends FunSuite {
test("Remote - different origin, cors parent different authority".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://bar.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://bar.org"))
).unsafeRunSync()
}

test("Remote - different origin, cors parent different scheme".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "https://foo.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "https://foo.org"))
).unsafeRunSync()
}

test("Remote - different origin, cors parent different port".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org:8080"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org:8080"))
).unsafeRunSync()
}

test("Remote - different origin, cors parent different port 2".fail) {
CorsComplianceCheck[IO](Remote(fooOrigin8080, null),
Remote(barOrigin, null),
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))).unsafeRunSync()
Headers.of(Header("Access-Control-Allow-Origin", "http://foo.org"))
).unsafeRunSync()
}

test("Local") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ class ImportResolutionSuite extends FunSuite {
val cached = parse("let x = 1 in x")
val expected = parse("let x = 2 in x")
val encoded = cached.normalize.alphaNormalize.getEncodedBytes
val hash = MessageDigest.getInstance("SHA-256").digest(expected.normalize.getEncodedBytes) //Hash doesn't match what is stored
val hash =
MessageDigest
.getInstance("SHA-256")
.digest(expected.normalize.getEncodedBytes) //Hash doesn't match what is stored

val expr =
parse(
Expand Down
3 changes: 2 additions & 1 deletion modules/scala/src/main/scala/org/dhallj/ast/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,8 @@ object UnionType extends Constructor[Map[String, Option[Expr]]] {
protected[this] val extractor: ExternalVisitor[Option[Result]] =
new OptionVisitor[Result] {
override def onUnionType(fields: JIterable[JMap.Entry[String, Expr]],
size: Int): Option[Map[String, Option[Expr]]] =
size: Int
): Option[Map[String, Option[Expr]]] =
Some(fields.asScala.map(entryToOptionTuple).toMap)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ trait ArbitraryInstances {
genType(defaultMaxDepth).flatMap(tpe =>
genForType(tpe).map(_.map(expr => Annotated(expr, tpe))).getOrElse(genType(defaultMaxDepth))
)
*/
*/
)
.map(WellTypedExpr(_))
)
Expand Down
16 changes: 4 additions & 12 deletions tests/src/main/scala/org/dhallj/tests/CheckersFunSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,13 @@ class CheckersFunSuite(
f: A => P,
testConfig: Test.Parameters = defaultTestConfig,
prettyConfig: Pretty.Params = defaultPrettyConfig
)(implicit
loc: Location,
tp: P => Prop,
AA: Arbitrary[A],
AS: Shrink[A],
AP: A => Pretty): Unit = check(Prop.forAll(f)(tp, AA, AS, AP), testConfig, prettyConfig)
)(implicit loc: Location, tp: P => Prop, AA: Arbitrary[A], AS: Shrink[A], AP: A => Pretty): Unit =
check(Prop.forAll(f)(tp, AA, AS, AP), testConfig, prettyConfig)

def testAll1[A, P](name: String)(
f: A => P,
testConfig: Test.Parameters = defaultTestConfig,
prettyConfig: Pretty.Params = defaultPrettyConfig
)(implicit
loc: Location,
tp: P => Prop,
AA: Arbitrary[A],
AS: Shrink[A],
AP: A => Pretty): Unit = test(name)(check1(f, testConfig, prettyConfig))
)(implicit loc: Location, tp: P => Prop, AA: Arbitrary[A], AS: Shrink[A], AP: A => Pretty): Unit =
test(name)(check1(f, testConfig, prettyConfig))
}

0 comments on commit d06893e

Please sign in to comment.