Skip to content

SCALA-455 Add code for scalafix article #1410

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

Merged
merged 1 commit into from
Jun 30, 2024
Merged
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
8 changes: 8 additions & 0 deletions scala-sbt/scalafix/.scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
rules = [
DisableSyntax,
RemoveUnused,
]

DisableSyntax.noVars = true
DisableSyntax.noThrows = true
DisableSyntax.noNulls = true
9 changes: 9 additions & 0 deletions scala-sbt/scalafix/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lazy val root = (project in file("."))
.settings(
name := "scalafix",
scalaVersion := "3.4.2",
version := "1.0.0",
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalacOptions += "-Wunused:all"
)
1 change: 1 addition & 0 deletions scala-sbt/scalafix/project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version=1.10.0
1 change: 1 addition & 0 deletions scala-sbt/scalafix/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.12.1")
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.baeldung.scala.scalafix

object DisableSyntaxDemo:
var myVariable = null

def validateMyVariable(): Boolean =
if (myVariable == null) throw Exception("myVariable Is Null")

return true

object DisableSyntaxDemoRewritten:
val myVariable = Option.empty[Unit]

def validateMyVariable(): Either[String, Unit] =
myVariable.toRight("myVariable Is Null")
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.baeldung.scala.scalafix

import scala.List

object RemoveUnusedDemo:
val myNumber = 10

def greeting(name: String): String = {
val newName = s"$name $myNumber"
s"Hello, $name!"
}

/* Rewritten:
object RemoveUnusedDemo:
val myNumber = 10

def greeting(name: String): String = {
s"$name $myNumber"
s"Hello, $name!"
}
*/