Skip to content

Commit 0a4cf49

Browse files
committed
Bring scalafix to project
1 parent e052916 commit 0a4cf49

5 files changed

Lines changed: 26 additions & 12 deletions

File tree

.scalafix.conf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
rules = [
2+
DisableSyntax,
3+
RedundantSyntax,
4+
//ExplicitResultTypes // not yet compatible with Scala3
5+
]
6+
DisableSyntax.noVars = true
7+
DisableSyntax.noThrows = true
8+
DisableSyntax.noNulls = true
9+
DisableSyntax.noReturns = true
10+
DisableSyntax.noWhileLoops = true
11+
DisableSyntax.noAsInstanceOf = true
12+
DisableSyntax.noIsInstanceOf = true

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.3")
66
addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")
77
//addSbtPlugin("com.typesafe.play" % "sbt-twirl" % "1.6.0-M7")
88
addSbtPlugin("com.typesafe.play" % "sbt-twirl" % "1.6.0-RC1")
9+
10+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.4")

src/main/scala/fr/janalyse/cem/Execute.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object Execute {
2828

2929
def makeCommandProcess(command: List[String], workingDir: Path) = {
3030
val results = for {
31-
executable <- ZIO.from(command.headOption).orElseFail(RunFailure(s"Example command is invalid"))
31+
executable <- ZIO.from(command.headOption).orElseFail(RunFailure("Example command is invalid"))
3232
arguments = command.drop(1)
3333
process <- ZIO.acquireRelease(
3434
Command(executable, arguments*)
@@ -48,9 +48,9 @@ object Execute {
4848

4949
def makeRunCommandProcess(example: CodeExample) = {
5050
for {
51-
exampleFilePath <- ZIO.fromOption(example.filepath).orElseFail(RunFailure(s"Example has no path for its content"))
52-
workingDir <- ZIO.fromOption(exampleFilePath.parent).orElseFail(RunFailure(s"Example file path content has no parent directory"))
53-
absoluteFileName <- exampleFilePath.toAbsolutePath.orElseFail(RunFailure(s"Example absolute file path error"))
51+
exampleFilePath <- ZIO.fromOption(example.filepath).orElseFail(RunFailure("Example has no path for its content"))
52+
workingDir <- ZIO.fromOption(exampleFilePath.parent).orElseFail(RunFailure("Example file path content has no parent directory"))
53+
absoluteFileName <- exampleFilePath.toAbsolutePath.orElseFail(RunFailure("Example absolute file path error"))
5454
command <- ZIO
5555
.from(
5656
example.runWith
@@ -65,8 +65,8 @@ object Execute {
6565

6666
def makeTestCommandProcess(example: CodeExample) = {
6767
for {
68-
exampleFilePath <- ZIO.fromOption(example.filepath).orElseFail(RunFailure(s"Example has no path for its content"))
69-
workingDir <- ZIO.fromOption(exampleFilePath.parent).orElseFail(RunFailure(s"Example file path content has no parent directory"))
68+
exampleFilePath <- ZIO.fromOption(example.filepath).orElseFail(RunFailure("Example has no path for its content"))
69+
workingDir <- ZIO.fromOption(exampleFilePath.parent).orElseFail(RunFailure("Example file path content has no parent directory"))
7070
command <- ZIO.succeed(example.testWith.getOrElse(s"sleep ${timeoutDuration.getSeconds()}").trim.split("\\s+").toList)
7171
results <- makeCommandProcess(command, workingDir) @@ annotated("example-test-command" -> command.mkString(" "))
7272
} yield results
@@ -79,7 +79,7 @@ object Execute {
7979
runEffect = makeRunCommandProcess(example).disconnect
8080
.timeout(timeoutDuration)
8181
testEffect = makeTestCommandProcess(example)
82-
.filterOrFail(result => result.exitCode == 0)(RunFailure(s"test code is failing"))
82+
.filterOrFail(result => result.exitCode == 0)(RunFailure("test code is failing"))
8383
.retry(Schedule.exponential(100.millis, 2).jittered && Schedule.recurs(5))
8484
.delay(testStartDelay)
8585
.disconnect
@@ -92,7 +92,7 @@ object Execute {
9292
success = exitCodeOption.exists(_ == 0) || (example.shouldFail && exitCodeOption.exists(_ != 0))
9393
runState = if timeout then "timeout" else if success then "success" else "failure"
9494
_ <- if (results.isLeft) ZIO.logError(s"""Couldn't execute either run or test part\n${results.swap.toOption.getOrElse("")}""") else ZIO.succeed(())
95-
_ <- if (!success) ZIO.logWarning(s"example run $runState\nFailed cause:\n$output") else ZIO.log(s"example run success")
95+
_ <- if (!success) ZIO.logWarning(s"example run $runState\nFailed cause:\n$output") else ZIO.log("example run success")
9696
} yield RunStatus(
9797
example = example,
9898
exitCodeOption = exitCodeOption,

src/main/scala/fr/janalyse/cem/tools/Hashes.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
package fr.janalyse.cem.tools
1717

1818
object Hashes {
19+
// TODO Migrate to an effect
1920
def sha1(that: String): String = {
2021
import java.math.BigInteger
2122
import java.security.MessageDigest
2223
// Inspired from https://alvinalexander.com/source-code/scala-method-create-md5-hash-of-string
23-
val content = if (that == null) "" else that // TODO - probably discutable, migrate to an effect
24-
val md = MessageDigest.getInstance("SHA-1") // TODO - can fail => potential border side effect !
24+
val content = that
25+
val md = MessageDigest.getInstance("SHA-1")
2526
val digest = md.digest(content.getBytes)
2627
val bigInt = new BigInteger(1, digest)
2728
val hashedString = bigInt.toString(16)

src/test/scala/fr/janalyse/cem/tools/HashesSpec.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class HashesSpec extends ZIOSpecDefault {
3535
},
3636
// ----------------------------------------------------------------------------------------------
3737
test("sha1 should not fail") {
38-
assertTrue(sha1("") == "da39a3ee5e6b4b0d3255bfef95601890afd80709") &&
39-
assertTrue(sha1(null) == "da39a3ee5e6b4b0d3255bfef95601890afd80709")
38+
assertTrue(sha1("") == "da39a3ee5e6b4b0d3255bfef95601890afd80709")
4039
},
4140
// ----------------------------------------------------------------------------------------------
4241
test("sha1 hashes are never empty") {

0 commit comments

Comments
 (0)