Skip to content
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

Add isAtomic to ScalafixPatch interface #1892

Merged
merged 2 commits into from
Nov 16, 2023
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
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