-
Notifications
You must be signed in to change notification settings - Fork 185
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
Respect the intent of rules authors when returning atomic patches #1261
Conversation
In scalafixFileEvaluation, there is a possibility to apply only some patches. The current issue, is that we were returning the low level patches, by recursively decomposing even Atomic patches. If the author rule has created an atomic patch that contains two Add patches, we should not decompose it, and therefore `previewPatches()` can only be called with "atomic" patches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even with ?w=1
the diff is really hard to follow, and I feel like many changes are unnecessary or could be extracted to no-op refactoring commits. Is there any chance you could amend it to try to produce a minimal diff? Thanks!
} | ||
} | ||
|
||
class CommentFileRule2 extends v1.SyntacticRule("CommentFileRule2") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class CommentFileRule2 extends v1.SyntacticRule("CommentFileRule2") { | |
class CommentFileAtomic extends v1.SyntacticRule("CommentFileAtomic") { |
val fileEvaluation1 = run1.evaluate().getFileEvaluations.head | ||
val patches1 = fileEvaluation1.getPatches | ||
assert(patches1.length == 2) | ||
val obtained1 = fileEvaluation1.previewPatches().get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no assertion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didi an assertion
assertNoDiff(obtained1, obtained2)
@@ -214,6 +213,74 @@ class ScalafixArgumentsSuite extends AnyFunSuite with DiffAssertions { | |||
assert(contentAfterRun == fileEvaluation.previewPatches().get) | |||
} | |||
|
|||
test("ScalafixArguments.evaluate retrieve only atomic patches") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think tests would be more readable (and avoid 1/2 suffixes in variables) if you had more tests with less assertions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
@@ -191,6 +200,20 @@ object PatchInternals { | |||
loop(patch) | |||
} | |||
|
|||
// don't decompose Atomic Patch | |||
def foreachPatchUnit(patch: Patch)(f: Patch => Unit): Unit = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a very generic signature, yet it's used only for accumulation, maybe the 2 new methods could be merged?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use it twice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I will amend to reduce the diff.
@@ -374,7 +374,7 @@ object MainOps { | |||
ctx: RuleCtx, | |||
index: Option[v0.SemanticdbIndex] | |||
): Option[String] = | |||
Try(tokenPatchApply(ctx, index, patches)).toOption | |||
Try(patchApply(ctx, index, patches)).toOption |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is in fact a rename.
I removed all my small refactoring (renames, and removing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for taking the time to amend, much clearer 👍
In scalafixFileEvaluation, there is a possibility to apply only some patches.
The current issue, is that we were returning the low level patches, by recursively decomposing even Atomic patches.
If the author rule has created an atomic patch that contains two Add patches, we should not decompose it,
and therefore
previewPatches()
can only be called with "atomic" patches