Skip to content

Commit

Permalink
Merge pull request #1892 from LaurenceWarne/add-is-atmoic-to-patch-api
Browse files Browse the repository at this point in the history
Add isAtomic to ScalafixPatch interface
  • Loading branch information
bjaglin authored Nov 16, 2023
2 parents 1d1d475 + 5163ead commit 52e1933
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ metals.sbt

# Scala CLI specific
.scala-build/

# Emacs Backups
*~
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ case class ScalafixPatchImpl(patch: Patch)(
): ScalafixTextEdit
}
.toArray

override def isAtomic: Boolean =
patch.isInstanceOf[Patch.internal.AtomicPatch]
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ public interface ScalafixPatch {
default ScalafixTextEdit[] textEdits() {
throw new UnsupportedOperationException("textEdits() is not implemented");
}

/**
*
* @return True if this patch is atomic, else false.
*/
default boolean isAtomic() {
throw new UnsupportedOperationException("isAtomic() is not implemented");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import scalafix.interfaces.ScalafixDiagnostic
import scalafix.interfaces.ScalafixFileEvaluationError
import scalafix.interfaces.ScalafixMainCallback
import scalafix.interfaces.ScalafixMainMode
import scalafix.interfaces.ScalafixPatch
import scalafix.internal.interfaces.ScalafixArgumentsImpl
import scalafix.internal.rule.RemoveUnused
import scalafix.internal.rule.RemoveUnusedConfig
Expand Down Expand Up @@ -572,6 +573,27 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions {
)
}

test("ScalafixPatch isAtomic") {
val cwd: Path = StringFS
.string2dir(
"""|/src/Main.scala
|
|object Main extends App""".stripMargin,
charset
)
.toNIO
val src = cwd.resolve("src")

def patches(rules: List[String]): Array[ScalafixPatch] = {
val run = api.withRules(rules.asJava).withSourceroot(src)
val fileEvaluation = run.evaluate().getFileEvaluations.head
fileEvaluation.getPatches
}

assert(patches(List("CommentFileAtomic")).forall(_.isAtomic))
assert(patches(List("CommentFileNonAtomic")).forall(!_.isAtomic))
}

test("com.github.liancheng::organize-imports is ignored") {
val rules = api
.withToolClasspath(
Expand Down

0 comments on commit 52e1933

Please sign in to comment.